I used this code (from Unity Scripting API reference) [ Mesh.CombineMeshes ] :
MeshFilter[ ] meshFilters = GetComponentsInChildren();
CombineInstance[ ] combine = new CombineInstance[meshFilters.Length];
int k = 0;
while (k < meshFilters.Length) {
combine[k].mesh = meshFilters[k].sharedMesh;
combine[k].transform = meshFilters[k].transform.localToWorldMatrix;
meshFilters[k].gameObject.active = false;
k++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
The mesh is combined OK however it’s positioned far away from the gameObject’s pivot. So after running the code, the gameObject seems to disappear but in fact its new combined mesh is rendered at some distance far away from its pivot.
I think there is something wrong with the combine[k].transform . At least this is not my code, it’s the code from the scripting reference. I guessed the code was tested against some simple model but failed to work with my models. Could you please suggest something to solve this? Thanks for your help.