# SetSubMeshes

> Sets information defining all sub-meshes in this Mesh, replacing any existing sub-meshes.

## Definition

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

## SetSubMeshes(SubMeshDescriptor\[], int, int, MeshUpdateFlags)

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes(SubMeshDescriptor[] desc, int start, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default)
```

### Parameters

**** (\[SubMeshDescriptor\[]]\(/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor)): An array or list of sub-mesh data descriptors.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the first element to take from the array or list in `desc`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements to take from the array or list in `desc`.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetSubMeshes(SubMeshDescriptor\[], MeshUpdateFlags)

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes(SubMeshDescriptor[] desc, MeshUpdateFlags flags = MeshUpdateFlags.Default)
```

### Parameters

**** (\[SubMeshDescriptor\[]]\(/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor)): An array or list of sub-mesh data descriptors.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetSubMeshes(List\<SubMeshDescriptor>, int, int, MeshUpdateFlags)

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes(List<SubMeshDescriptor> desc, int start, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default)
```

### Parameters

**** (\[List\<SubMeshDescriptor>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): An array or list of sub-mesh data descriptors.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the first element to take from the array or list in `desc`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements to take from the array or list in `desc`.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetSubMeshes(List\<SubMeshDescriptor>, MeshUpdateFlags)

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes(List<SubMeshDescriptor> desc, MeshUpdateFlags flags = MeshUpdateFlags.Default)
```

### Parameters

**** (\[List\<SubMeshDescriptor>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): An array or list of sub-mesh data descriptors.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

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

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes<T>(NativeArray<T> desc, int start, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): An array or list of sub-mesh data descriptors.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Index of the first element to take from the array or list in `desc`.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of elements to take from the array or list in `desc`.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

## SetSubMeshes\<T>(NativeArray\<T>, MeshUpdateFlags)

Sets information defining all sub-meshes in this [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md), replacing any existing sub-meshes.

```csharp
public void SetSubMeshes<T>(NativeArray<T> desc, MeshUpdateFlags flags = MeshUpdateFlags.Default) where T : struct
```

### Parameters

**** (\[NativeArray\<T>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): An array or list of sub-mesh data descriptors.**** (\[MeshUpdateFlags]\(/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags)): (Optional) Flags controlling the function behavior, see [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).

### Remarks

Note that [Mesh.SetSubMeshes](/engine/6000.7/script-reference/unityengine/mesh/setsubmeshes.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md), and [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md) are designed for maximum performance. These functions operate on the underlying mesh data structures involving raw index buffers, vertex buffers and mesh subset data. When you use these methods, Unity performs very little data validation, so you must ensure your data is valid.

In particular, you must ensure that the [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) index ranges and [SubMeshDescriptor.topology](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor/topology.md) values are set to correct values. SubMesh indices, both indexStart and indexCount, must not overlap with any other SubMesh indices.

You must also ensure that for each of the SubMesh's meshLod the lodrange is contained within the newly set index range. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the SubMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md). If using Mesh LODs, you must also ensure that the provided index range for each of the sub-meshes is large enough to contain all levels of detail used within that sub-mesh. You may be required to invoke [Mesh.SetLods](/engine/6000.7/script-reference/unityengine/mesh/setlods.md) prior to setting the subMesh. You can disable validation by setting flags to [MeshUpdateFlags.DontValidateLodRanges](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontvalidatelodranges.md).

For information about the difference between the simpler and more advanced methods of assigning data to a Mesh from script, see [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md).

The SubMeshDescriptor-bounds, SubMeshDescriptor-firstVertex and SubMeshDescriptor-vertexCount values of [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md) are calculated automatically by `SetSubMeshes`, unless [MeshUpdateFlags.DontRecalculateBounds](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags/dontrecalculatebounds.md) flag is passed. Note that this only applies to the bounds of the SubMesh. You must call [Mesh.RecalculateBounds](/engine/6000.7/script-reference/unityengine/mesh/recalculatebounds.md) to recalculate the bounds of the Mesh itself.

General usage pattern is:

```csharp
var mesh = new Mesh();

// setup vertex buffer data
mesh.vertices = ...;

// set index buffer
mesh.SetIndexBufferParams(...);
mesh.SetIndexBufferData(...);

// setup information about mesh subsets
SubMeshDescriptor[] sm = new SubMeshDescriptor[] {...}
mesh.SetSubMeshes(sm);

// update bounds of the mesh
mesh.RecalculateBounds();
```

For details on what data to set up for each sub-mesh, see [SubMeshDescriptor](/engine/6000.7/script-reference/unityengine/rendering/submeshdescriptor.md).

Additional Resources: [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/getsubmesh.md), [Mesh.SetSubMesh](/engine/6000.7/script-reference/unityengine/mesh/setsubmesh.md), [Mesh.SetIndexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferparams.md), [Mesh.SetIndexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setindexbufferdata.md), [MeshUpdateFlags](/engine/6000.7/script-reference/unityengine/rendering/meshupdateflags.md).
