# GetVertexData<T>(int)

> Gets raw data for a given vertex buffer stream format in the MeshData.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.5/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public NativeArray<T> GetVertexData<T>(int stream = 0) where T : struct
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The vertex buffer stream to get data for. The default value is 0.

### Returns

| Type                                                                                 | Description                                                |
| ------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
| [NativeArray\<T>](/engine/6000.5/script-reference/unity/collections/nativearray1.md) | Returns a `NativeArray` containing the vertex buffer data. |

### Remarks

GetVertexData returns a direct "pointer" into the raw vertex buffer data without any memory allocations, data copies or conversions. You do not need to dispose of the returned `NativeArray`, because it does not represent a new memory allocation.

You need to know the exact Mesh data layout to do this: for instance, the presence and formats of all the mesh vertex attributes. The data layout matches the one from [Mesh.SetVertexBufferData](/engine/6000.5/script-reference/unityengine/mesh/setvertexbufferdata.md).

If the `MeshData` is writeable, and you have set the vertex buffer size and layout using [Mesh.MeshData.SetVertexBufferParams](/engine/6000.5/script-reference/unityengine/mesh/meshdata/setvertexbufferparams.md), you can write vertex data directly to the array. If the `MeshData` is read-only, the array is read-only.

Additional Resources: [Mesh.AllocateWritableMeshData](/engine/6000.5/script-reference/unityengine/mesh/allocatewritablemeshdata.md), [Mesh.AcquireReadOnlyMeshData](/engine/6000.5/script-reference/unityengine/mesh/acquirereadonlymeshdata.md), [Mesh.MeshData.SetVertexBufferParams](/engine/6000.5/script-reference/unityengine/mesh/meshdata/setvertexbufferparams.md).

```csharp
using UnityEngine;
public class ExampleScript : MonoBehaviour
{
    struct Vertex
    {
        public Vector3 pos;
        public Vector2 uv;
    }
    void Start()
    {
        var mesh = new Mesh();
        mesh.vertices = new[] {Vector3.one, Vector3.up};
        mesh.uv = new[] {Vector2.right, Vector2.up};
        using (var data = Mesh.AcquireReadOnlyMeshData(mesh))
        {
            var verts = data[0].GetVertexData<Vertex>();
            // prints "pos (1.0, 1.0, 1.0) uv (1.0, 0.0)" and "pos (0.0, 1.0, 0.0) uv (0.0, 1.0)"
            foreach (var v in verts)
                Debug.Log($"pos {v.pos} uv {v.uv}");
        }
    }
}
```

Additional Resources: [Mesh.SetVertexBufferParams](/engine/6000.5/script-reference/unityengine/mesh/setvertexbufferparams.md), [Mesh.SetVertexBufferData](/engine/6000.5/script-reference/unityengine/mesh/setvertexbufferdata.md), [GetIndexData](/engine/6000.5/script-reference/unityengine/mesh/meshdata/getindexdata.md), [Mesh.AcquireReadOnlyMeshData](/engine/6000.5/script-reference/unityengine/mesh/acquirereadonlymeshdata.md).
