Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetVertexAttributeOffset(VertexAttribute)

Get offset within a vertex buffer stream of a specific vertex data attribute on this Mesh.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public int GetVertexAttributeOffset(VertexAttribute attr)

Parameters

The vertex data attribute to check for.

Returns

Type

Description

intThe byte offset within a atream of the data attribute, or -1 if it is not present.

Remarks

Meshes usually use a single vertex buffer stream, but it is possible to set up a vertex layout where attributes use different vertex buffers (see Mesh.SetVertexBufferParams). When you use such a layout, use this function to query where a given attribute is located in a stream.
Note that this function returns the byte offset within a stream, without specifying which stream. To identify the stream that contains a given attribute, use Mesh.GetVertexAttributeStream.
using UnityEngine;using UnityEngine.Rendering;public class ExampleScript : MonoBehaviour{ void Start() { // Create a Mesh with custom vertex data layout: // position and normal go into stream 0, // color goes into stream 1. var mesh = new Mesh(); mesh.SetVertexBufferParams(10, new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3, stream:0), new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3, stream:0), new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.UNorm8, 4, stream:1)); // Prints offsets: 0, 12, 0 Debug.Log($"Position offset {mesh.GetVertexAttributeOffset(VertexAttribute.Position)}"); Debug.Log($"Normal offset {mesh.GetVertexAttributeOffset(VertexAttribute.Normal)}"); Debug.Log($"Color offset {mesh.GetVertexAttributeOffset(VertexAttribute.Color)}"); // Cleanup Object.DestroyImmediate(mesh); }}