Do you want to combine meshes into one single mesh in Unity? This tutorial explains how to use unity's CombineMeshes function to do that.

Combine meshes in Unity.

mesh

using System.Collections.Generic;
using UnityEngine;

public class App : MonoBehaviour
{
    public Mesh Mesh1;
    public Mesh Mesh2;

    private void Start()
    {
        var mesh = CombineMeshes(new List<Mesh> { Mesh1, Mesh2 });
        GetComponent<MeshFilter>().mesh = mesh;
    }

    private Mesh CombineMeshes(List<Mesh> meshes)
    {
        var combine = new CombineInstance[meshes.Count];
        for (int i = 0; i < meshes.Count; i++)
        {
            combine[i].mesh = meshes[i];
            combine[i].transform = transform.localToWorldMatrix;
        }

        var mesh = new Mesh();
        mesh.CombineMeshes(combine);
        return mesh;
    }
}

drag

Written by Loek van den Ouweland on 2017-12-01.
Questions regarding this artice? You can send them to the address below.