# GetIndexData<T>()

> Gets raw data from the index buffer of the MeshData.

## Definition

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

```csharp
public NativeArray<T> GetIndexData<T>() where T : struct
```

### Returns

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

### Remarks

GetIndexData returns a direct "pointer" into the raw index 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 work with this data, including the presence and formats of all vertex attributes. The data layout matches the one from [Mesh.SetIndexBufferData](/engine/6000.0/script-reference/unityengine/mesh/setindexbufferdata.md). Typically, Meshes with a 16 bit index format use the ushort data type, and Meshes with a 32 bit index format use the int data type.

If the MeshData is writeable, and you have set the index buffer size and format using [Mesh.MeshData.SetIndexBufferParams](/engine/6000.0/script-reference/unityengine/mesh/meshdata/setindexbufferparams.md), you can write indices directly to the array. If the MeshData is read-only, the array is read-only.

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

```csharp
using UnityEngine;
using UnityEngine.Rendering;
public class ExampleScript : MonoBehaviour
{
    void Start()
    {
        var mesh = new Mesh();
        mesh.vertices = new[] {Vector3.one, Vector3.zero, Vector3.up};
        mesh.indexFormat = IndexFormat.UInt16;
        mesh.triangles = new[] {2, 0, 1};
        using (var data = Mesh.AcquireReadOnlyMeshData(mesh))
        {
            var indices = data[0].GetIndexData<ushort>();
            // prints 2, 0, 1
            foreach (var i in indices)
                Debug.Log(i);
        }
    }
}
```

Additional Resources: [Mesh.SetIndexBufferParams](/engine/6000.0/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.0/script-reference/unityengine/mesh/setindexbufferdata.md), [GetVertexData](/engine/6000.0/script-reference/unityengine/mesh/meshdata/getvertexdata.md), [Mesh.AcquireReadOnlyMeshData](/engine/6000.0/script-reference/unityengine/mesh/acquirereadonlymeshdata.md).
