Hello I am using this guy's script https://www.youtube.com/watch?v=wYAlky1aZn4 to combine meshes because the game is "lagging" or whatever it's called when the when it doesn't run smooth. I have 34*124 cubes with two different meshes and all works perfect if I put the script on a object with 34*20 childern (the same cubes that I mentioned before) but if I put it on the object that has 32*124 children it turnes them into something that looks like it has 34*20 cubes.
Basically it if I put the script on something that has more childern it turns it into something smaller.
This is the code from the video:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CombineMeshes : MonoBehaviour {
public void Combine(){
Quaternion oldRot = transform.rotation;
Vector3 oldPos = transform.position;
transform.rotation = Quaternion.identity;
transform.position = Vector3.zero;
MeshFilter[] filters = GetComponentsInChildren<MeshFilter> ();
Mesh finalMesh = new Mesh ();
CombineInstance[] combiners = new CombineInstance[filters.Length];
for (int a = 0; a < filters.Length; a++) {
if (filters [a].transform == transform) {
continue;
}
combiners [a].subMeshIndex = 0;
combiners [a].mesh = filters [a].sharedMesh;
combiners [a].transform = filters [a].transform.localToWorldMatrix;
}
finalMesh.CombineMeshes (combiners);
GetComponent<MeshFilter> ().sharedMesh = finalMesh;
transform.rotation = oldRot;
transform.position = oldPos;
for (int a= 0; a < transform.childCount; a++) {
transform.GetChild (a).gameObject.SetActive (false);
}
}
}
That is exactly the vertex limit problem you are having. With your set up 1 mesh can have only
34*20*96 = 65.280
vertices. After that you need another mesh.124*34*96
makes404,736
and is over the limit. Therefore, you need to change format of your mesh toUInt32
. If the lag continues i can try to help further. Good luck!