REW

How Do I Merge Two Shapes In Unity?

Published Aug 29, 2025 4 min read
On this page

There are three main methods for merging shapes in Unity, each with its own use case: using the ProBuilder package for manual merging in the editor, writing a script to combine meshes for runtime optimization, and simple parenting for organizational purposes.

Method 1: Merging with ProBuilder (Recommended for editing)

ProBuilder is a powerful package that turns Unity into a powerful, in-engine 3D modeling tool. It is the best method for merging shapes and performing other boolean operations directly in the editor.

Step 1: Install ProBuilder

  1. In the Unity Editor, open the Package Manager by navigating to Window > Package Manager.
  2. In the search bar, enter "ProBuilder" and select the ProBuilder package.
  3. Click the Install button.

Step 2: Convert objects to ProBuilder meshes

  1. Select all the GameObjects you wish to merge in the Hierarchy.
  2. Go to Tools > ProBuilder > ProBuilderize to convert them into editable ProBuilder meshes.

Step 3: Merge the meshes

  1. Ensure all the ProBuilder objects are still selected in the Hierarchy.
  2. Navigate to Tools > ProBuilder > Object > Merge Objects.
  3. ProBuilder will combine the selected objects into a single mesh and create a new GameObject to hold it. You can now delete the original objects.

Pros of using ProBuilder:

  • Provides a clean, single mesh result.
  • Enables other powerful mesh editing tools like subdivision and extrusions.
  • The Boolean (CSG) Tool (an experimental feature) offers more advanced operations like union, subtraction, and intersection.

Cons of using ProBuilder:

  • Requires a bit of setup.
  • Not suitable for merging objects at runtime.

Method 2: Combining meshes with a script (Recommended for runtime optimization)

For situations that require meshes to be merged during gameplay (e.g., dynamically generated terrain or levels), you can write a script to combine them. This technique is often used to reduce draw calls and improve performance. A common pattern is to create an empty parent object and merge all of its children into a single mesh.

Step 1: Create a C# script

Create a new C# script named MeshCombiner.

Step 2: Add the combining code

Copy and paste the following code into your MeshCombiner script. This script will combine the meshes of all child objects into a single mesh on the parent object.

using UnityEngine;
using System.Collections.Generic;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class MeshCombiner : MonoBehaviour
{
    public bool combineOnAwake = true;
    void Awake()
    {
        if (combineOnAwake)
        {
            CombineMeshes();
        }
    }
    [ContextMenu("Combine Meshes Now")]
    public void CombineMeshes()
    {
        // Get all mesh filters from the children
        MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        var combine = new List<CombineInstance>();
        // Iterate through each child's mesh
        foreach (var filter in meshFilters)
        {
            if (filter.gameObject == this.gameObject) continue; // Skip the parent
            // Create a CombineInstance for each sub-mesh
            for (int sub = 0; sub < filter.sharedMesh.subMeshCount; sub++)
            {
                CombineInstance combineInstance = new CombineInstance
                {
                    mesh = filter.sharedMesh,
                    subMeshIndex = sub,
                    transform = filter.transform.localToWorldMatrix
                };
                combine.Add(combineInstance);
            }
            filter.gameObject.SetActive(false); // Hide the original child meshes
        }
        // Combine the meshes into a single mesh
        Mesh mesh = new Mesh();
        mesh.CombineMeshes(combine.ToArray());
        // Assign the new mesh to this object's MeshFilter
        GetComponent<MeshFilter>().mesh = mesh;
        GetComponent<MeshRenderer>().material = meshFilters[1].GetComponent<MeshRenderer>().sharedMaterial;
        Debug.Log("Combined " + (combine.Count) + " meshes.");
    }
}

Use code with caution.

Step 3: Apply the script

  1. Create an empty GameObject in your scene. This will be the parent object.
  2. Drag the two shapes you want to merge onto the parent GameObject to make them children.
  3. Add a MeshFilter and MeshRenderer component to the parent GameObject.
  4. Drag your MeshCombiner script onto the parent GameObject.
  5. With the parent GameObject selected, click the component's context menu (the three vertical dots) and choose Combine Meshes Now. You can also check Combine On Awake to have the merge happen when the scene starts.

Pros of using a script:

  • Enables dynamic merging during gameplay.
  • Great for performance optimization by reducing draw calls.
  • Ideal for procedural generation.

Cons of using a script:

  • More complex to set up.
  • Requires scripting knowledge.
  • The original objects are hidden, not destroyed, which can be inefficient if not handled correctly.

Method 3: Simple parenting (Recommended for grouping)

This is the simplest form of "merging" and is only suitable for organization and treating multiple objects as a single unit without physically combining their meshes.

Step 1: Create a parent object

  1. Create an empty GameObject in your Hierarchy (GameObject > Create Empty).
  2. Rename it to something descriptive, like MergedShapes.

Step 2: Parent the shapes

  1. Drag the two GameObjects you want to merge onto the MergedShapes object in the Hierarchy. This makes them child objects.
  2. Now, when you move, rotate, or scale the MergedShapes parent object, both child objects will follow.

Step 3: Create a prefab (optional)

  1. Drag the MergedShapes parent object from the Hierarchy into your Project window to create a prefab.
  2. This allows you to create multiple instances of your merged shapes throughout your scene.

Pros of simple parenting:

  • Extremely easy and fast to do.
  • Maintains the individual properties of each child object.
  • Excellent for organizing complex scenes.

Cons of simple parenting:

  • Does not reduce draw calls, so it's not a performance optimization.
  • The objects remain separate meshes, which can be a problem if you need seamless geometry or boolean operations.
Enjoyed this article? Share it with a friend.