SetIndexBufferData
Sets the data of the mesh's index buffer directly copied from data source.
Read time 4 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- 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.
public void SetIndexBufferData<T>(NativeArray<T> data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
Parameters
The source data container containing the index data is copied.
The first element in the source data to copy from.
The first element in the mesh index buffer to receive the data.
The number of elements to copy from the data container into the Mesh buffer.
The optional MeshUpdateFlags 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 to define index ranges and topology, otherwise your mesh will not render.
By default, the array is validated for out-of-bounds indices. To disable validation for additional performance, set the parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.
dataflagsThis 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 or Mesh.SetIndices instead.
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}
SetIndexBufferData<T>(`<>[], int, int, int, MeshUpdateFlags)
Sets the data of the mesh's index buffer directly copied from data source.
public void SetIndexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
Parameters
The source data container containing the index data is copied.
The first element in the source data to copy from.
The first element in the mesh index buffer to receive the data.
The number of elements to copy from the data container into the Mesh buffer.
The optional MeshUpdateFlags 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 to define index ranges and topology, otherwise your mesh will not render.
By default, the array is validated for out-of-bounds indices. To disable validation for additional performance, set the parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.
dataflagsThis 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 or Mesh.SetIndices instead.
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}
SetIndexBufferData<T>(List<T>, int, int, int, MeshUpdateFlags)
Sets the data of the mesh's index buffer directly copied from data source.
public void SetIndexBufferData<T>(List<T> data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
Parameters
The source data container containing the index data is copied.
The first element in the source data to copy from.
The first element in the mesh index buffer to receive the data.
The number of elements to copy from the data container into the Mesh buffer.
The optional MeshUpdateFlags 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 to define index ranges and topology, otherwise your mesh will not render.
By default, the array is validated for out-of-bounds indices. To disable validation for additional performance, set the parameter to MeshUpdateFlags.DontValidateIndices. Only disable validation if you are certain your data is correct, as invalid indices can cause crashes or undefined behavior.
dataflagsThis 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 or Mesh.SetIndices instead.
{code Documentation/ManualDocs/com.unity.documentation-examples/Graphics/Scripts/Mesh/SetIndexBufferParamsExample.cs}