# GetIndices

> Fetches the index list for the specified sub-mesh.

## Definition

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

## GetIndices(int, bool)

Fetches the index list for the specified sub-mesh.

```csharp
public int[] GetIndices(int submesh, bool applyBaseVertex)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.

### Returns

| Type                                                           | Description              |
| -------------------------------------------------------------- | ------------------------ |
| [int\[\]](https://learn.microsoft.com/dotnet/api/system.int32) | Array with face indices. |

### Remarks

Each integer in the returned list is a vertex index, which is used as an offset into the Mesh's vertex arrays. See [Mesh.vertices](/engine/6000.3/script-reference/unityengine/mesh/vertices.md) and [Mesh.GetVertices](/engine/6000.3/script-reference/unityengine/mesh/getvertices.md). The layout of the indices depends on the [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md) of the sub-mesh. For example, a triangular mesh will return indices in multiples of three.

A sub-mesh represents a list of triangles (or indices with a different [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md)) that are rendered using a single [Material](/engine/6000.3/script-reference/unityengine/material.md). When the Mesh is used with a [Renderer](/engine/6000.3/script-reference/unityengine/renderer.md) that has multiple materials, you should ensure that there is one sub-mesh per Material.

Call the method overload with a `List` parameter if you control the life cycle of the index buffer and wish to avoid allocation of a new array with every access.

Additional Resources: [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetTopology](/engine/6000.3/script-reference/unityengine/mesh/gettopology.md), [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md) enum, [Mesh.AcquireReadOnlyMeshData](/engine/6000.3/script-reference/unityengine/mesh/acquirereadonlymeshdata.md) function.

## GetIndices(int, int, bool)

Fetches the index list for the specified sub-mesh.

```csharp
public int[] GetIndices(int submesh, int meshLod, bool applyBaseVertex = true)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The Mesh LOD index. Use -1 to get the entire sub-mesh.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.

### Returns

| Type                                                           | Description              |
| -------------------------------------------------------------- | ------------------------ |
| [int\[\]](https://learn.microsoft.com/dotnet/api/system.int32) | Array with face indices. |

### Remarks

Each integer in the returned list is a vertex index, which is used as an offset into the Mesh's vertex arrays. See [Mesh.vertices](/engine/6000.3/script-reference/unityengine/mesh/vertices.md) and [Mesh.GetVertices](/engine/6000.3/script-reference/unityengine/mesh/getvertices.md). The layout of the indices depends on the [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md) of the sub-mesh. For example, a triangular mesh will return indices in multiples of three.

A sub-mesh represents a list of triangles (or indices with a different [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md)) that are rendered using a single [Material](/engine/6000.3/script-reference/unityengine/material.md). When the Mesh is used with a [Renderer](/engine/6000.3/script-reference/unityengine/renderer.md) that has multiple materials, you should ensure that there is one sub-mesh per Material.

Call the method overload with a `List` parameter if you control the life cycle of the index buffer and wish to avoid allocation of a new array with every access.

Additional Resources: [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md), [Mesh.GetTopology](/engine/6000.3/script-reference/unityengine/mesh/gettopology.md), [MeshTopology](/engine/6000.3/script-reference/unityengine/meshtopology.md) enum, [Mesh.AcquireReadOnlyMeshData](/engine/6000.3/script-reference/unityengine/mesh/acquirereadonlymeshdata.md) function.

## GetIndices(List\<int>, int, bool)

Use this method overload if you control the life cycle of the list passed in and you want to avoid allocating a new array with every access.

```csharp
public void GetIndices(List<int> indices, int submesh, bool applyBaseVertex)
```

### Parameters

**** (\[List\<int>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list of indices to populate.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.

## GetIndices(List\<int>, int, int, bool)

Use this method overload if you control the life cycle of the list passed in and you want to avoid allocating a new array with every access.

```csharp
public void GetIndices(List<int> indices, int submesh, int meshLod, bool applyBaseVertex = false)
```

### Parameters

**** (\[List\<int>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list of indices to populate.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The Mesh LOD index.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.

## GetIndices(List\<ushort>, int, bool)

Use this method overload if you control the life cycle of the list passed in and you want to avoid allocating a new array with every access.

```csharp
public void GetIndices(List<ushort> indices, int submesh, bool applyBaseVertex = true)
```

### Parameters

**** (\[List\<ushort>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list of indices to populate.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.

## GetIndices(List\<ushort>, int, int, bool)

Use this method overload if you control the life cycle of the list passed in and you want to avoid allocating a new array with every access.

```csharp
public void GetIndices(List<ushort> indices, int submesh, int meshLod, bool applyBaseVertex = true)
```

### Parameters

**** (\[List\<ushort>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): A list of indices to populate.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The sub-mesh index. See [Mesh.subMeshCount](/engine/6000.3/script-reference/unityengine/mesh/submeshcount.md).**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The Mesh LOD index.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): True (default value) will apply base vertex offset to returned indices.
