- Home /
Why mesh colliders doesn't work with combined meshes using Mesh.CombineMeshes?
I have a bunch of meshes combined into a nice mesh using Mesh.CombineMeshes, to that mesh I add a mesh collider and it doesn't collide at all!
Answer by naruse · Mar 16, 2010 at 11:31 AM
Try so set the Convex flag. Some mesh Colliders wont work depending on how the mesh is defined.
Answer by Vorda · Mar 16, 2010 at 06:37 PM
Had the same problem yesterday, had two meshes using for colliders, separe work perfectly combined wouldn't work. My colliders once combined also didnt show the greenish collider outline in scene view after combining any more.
My fix was using Mesh.Optimize, after combining:
combineInstances.Clear(); CombineInstance cmb = new CombineInstance(); cmb.mesh = colisionMesh; combineInstances.Add(cmb); cmb = new CombineInstance(); cmb.mesh = walkMesh; combineInstances.Add(cmb);
Mesh col = new Mesh();
col.name = ModelName + "_C+W";
col.CombineMeshes(combineInstances.ToArray(), true, false);
col.Optimize();
Debug.Log("$3");
//foreach (CombineInstance c in combineInstances)
// UnityEngine.Object.DestroyImmediate(c.mesh);
MeshCollider mc = (MeshCollider)g.AddComponent(typeof(MeshCollider));
mc.sharedMesh = col;
return g;
ALTHOUGH i think it welds some vertices etc... so it kinda ruined my perfectly setup collision meshes :( anyone know is this a known bug in Unity, or? Note: combining meshes and displaying them instead of using as colliders works perfectly...
I reported this as a bug on 7/7/10 adding Optimize() didn't fix my example http://forum.unity3d.com/viewtopic.php?p=350153&highlight=#350153 cases: 364060 and 364291 (problems with skybox and combined mesh)
Doesn't sound like a bug. The greenish collider outline is from having the collider set as convex, but convex colliders have a vertex limit of 255.
Dear Vorda,
THAN$$anonymous$$ YOU THAN$$anonymous$$ YOU THAN$$anonymous$$ YOU THAN$$anonymous$$ YOU!
Worked like a charm :)
Answer by jonas-echterhoff · Oct 01, 2010 at 09:58 AM
This is a known bug in Unity 2.6, Mesh.CombineMeshes will not generate the collision information for the combined mesh. I believe this is fixed in 3.0, though.