# SetIndexBufferData

> Sets the data of the mesh's index buffer directly copied from data source.

## Definition

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

## SetIndexBufferData\<T>(NativeArray\<T>, int, int, int, MeshUpdateFlags)

Sets the data of the mesh's index buffer directly copied from data source.

```csharp
public void SetIndexBufferData<T>(NativeArray<T> data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The source data container containing the index data is copied.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the source data to copy from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the mesh index buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy from the data container into the Mesh buffer.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): The optional [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md) flags that control the update behavior of the mesh.

### Remarks

This method does not update sub-mesh ranges or sub-mesh count. You must configure sub-meshes separately via [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md) to define index ranges and topology, otherwise your mesh will not render.

By default, the `data` array is validated for out-of-bounds indices. To disable validation for additional performance, set the `flags` parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.

This is a high-performance, low-level method for populating mesh index data. It provides direct access to the underlying index buffer with minimal validation overhead, making it suitable for performance-critical scenarios where you need maximum control over mesh data.

For simpler ways to set indices that handle sub-mesh configuration automatically, use [Mesh.SetTriangles](/engine/6000.7/script-reference/unityengine/mesh/settriangles.md) or [Mesh.SetIndices](/engine/6000.7/script-reference/unityengine/mesh/setindices.md) instead.

```csharp
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}
```

Additional Resources: [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetVertexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetIndexBufferData\<T>(\`\<>\[], int, int, int, MeshUpdateFlags)

Sets the data of the mesh's index buffer directly copied from data source.

```csharp
public void SetIndexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
```

### Parameters

**** (\[\<T>\[]]\(./)): The source data container containing the index data is copied.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the source data to copy from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the mesh index buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy from the data container into the Mesh buffer.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): The optional [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md) flags that control the update behavior of the mesh.

### Remarks

This method does not update sub-mesh ranges or sub-mesh count. You must configure sub-meshes separately via [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md) to define index ranges and topology, otherwise your mesh will not render.

By default, the `data` array is validated for out-of-bounds indices. To disable validation for additional performance, set the `flags` parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.

This is a high-performance, low-level method for populating mesh index data. It provides direct access to the underlying index buffer with minimal validation overhead, making it suitable for performance-critical scenarios where you need maximum control over mesh data.

For simpler ways to set indices that handle sub-mesh configuration automatically, use [Mesh.SetTriangles](/engine/6000.7/script-reference/unityengine/mesh/settriangles.md) or [Mesh.SetIndices](/engine/6000.7/script-reference/unityengine/mesh/setindices.md) instead.

```csharp
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}
```

Additional Resources: [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetVertexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetIndexBufferData\<T>(List\<T>, int, int, int, MeshUpdateFlags)

Sets the data of the mesh's index buffer directly copied from data source.

```csharp
public void SetIndexBufferData<T>(List<T> data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
```

### Parameters

**** (\[List\<T>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): The source data container containing the index data is copied.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the source data to copy from.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The first element in the mesh index buffer to receive the data.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of elements to copy from the data container into the Mesh buffer.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): The optional [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md) flags that control the update behavior of the mesh.

### Remarks

This method does not update sub-mesh ranges or sub-mesh count. You must configure sub-meshes separately via [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md) to define index ranges and topology, otherwise your mesh will not render.

By default, the `data` array is validated for out-of-bounds indices. To disable validation for additional performance, set the `flags` parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.

This is a high-performance, low-level method for populating mesh index data. It provides direct access to the underlying index buffer with minimal validation overhead, making it suitable for performance-critical scenarios where you need maximum control over mesh data.

For simpler ways to set indices that handle sub-mesh configuration automatically, use [Mesh.SetTriangles](/engine/6000.7/script-reference/unityengine/mesh/settriangles.md) or [Mesh.SetIndices](/engine/6000.7/script-reference/unityengine/mesh/setindices.md) instead.

```csharp
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}
```

Additional Resources: [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetVertexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).
