# CombineInstance

> A struct that describes a single mesh to be merged with other instances into a combined mesh.

## Definition

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

```csharp
public struct CombineInstance
```

## Remarks

Use this `CombineInstance` struct with the [Mesh.CombineMeshes](/engine/6000.7/script-reference/unityengine/mesh/combinemeshes.md) method to merge multiple meshes into a single combined mesh. You must create a `CombineInstance` for each mesh you want to combine. If a mesh contains multiple sub-meshes, you must create a separate `CombineInstance` for each sub-mesh.

```csharp
using UnityEngine;

// This script combines the meshes from children into a single new Mesh.
// The combined mesh is assigned to the MeshFilter of this GameObject.
// The original meshes are not destroyed, but their GameObjects are disabled.

[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        CombineInstance[] instances = new CombineInstance[meshFilters.Length];

        for (int i = 0; i < meshFilters.Length; i++)
        {
            var meshFilter = meshFilters[i];

            instances[i] = new CombineInstance
            {
                mesh = meshFilter.sharedMesh,
                transform = meshFilter.transform.localToWorldMatrix,
            };

            meshFilter.gameObject.SetActive(false);
        }

        Mesh combinedMesh = new Mesh();
        combinedMesh.CombineMeshes(instances);
        gameObject.GetComponent<MeshFilter>().sharedMesh = combinedMesh;
        gameObject.SetActive(true);
    }
}
```

Additional Resources: [Mesh.CombineMeshes](/engine/6000.7/script-reference/unityengine/mesh/combinemeshes.md), [Mesh.subMeshCount](/engine/6000.7/script-reference/unityengine/mesh/submeshcount.md).

## Properties

| Property                                                                                                  | Description                                                                                           |
| --------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [lightmapScaleOffset](/engine/6000.7/script-reference/unityengine/combineinstance/lightmapscaleoffset.md) | The baked lightmap UV scale and offset applied to the Mesh.                                           |
| [mesh](/engine/6000.7/script-reference/unityengine/combineinstance/mesh.md)                               | The [Mesh](/engine/6000.7/script-reference/unityengine/mesh.md) to be combined with the other meshes. |
| [subMeshIndex](/engine/6000.7/script-reference/unityengine/combineinstance/submeshindex.md)               | The index of the sub-mesh to be combined with the other meshes.                                       |
| [transform](/engine/6000.7/script-reference/unityengine/combineinstance/transform.md)                     | A matrix used to transform vertices before combining meshes.                                          |
