Hey there! I’m a having a little problem using a Mesh.CombineMeshes and then add a MeshCollider component to the resulting mesh but in my game the collider doesn’t seem to be working. The collider component is added but it doesn’t seem to be colliding with anything.
I’ve tried using RecalculateBounds and RecalculateNormals after creating the combined mesh but that doesn’t seem to do anything.
Any help will be greatly appreciated.
If you’re combining the meshes at runtime, you need to set the MeshCollider’s sharedMesh property to reference the combined mesh.
Thanks for you reply. Sorry I didn’t reply before. Yeah, we already tried that and it didn’t work.
Mesh combinedMesh = new Mesh();
combinedMesh.name = "Combined Mesh";
combinedMesh.CombineMeshes(meshArray, true, true);
GameObject go = (GameObject) GameObject.Instantiate(resourceName);
MeshFilter mf = go.GetComponent<MeshFilter>();
mf.sharedMesh = combinedMesh;
MeshCollider mc = (MeshCollider) go.AddComponent(typeof(MeshCollider));
mc.sharedMesh = combinedMesh;
Something like that, right?
I’ve to use some spare free time to make a little project where this can be tested. I’ve also fill a bug report but i don’t know if my project got trough.
Case 314548
256154–9217–$meshcombine_148.zip (1.1 MB)
Hi Fran, did you found a solution ? Or did the UT guys answered you ?
Just out of curiosity: why do you need the physics to use the combined mesh?
The original meshes should still correspond to the combined one, so you could just use the original mesh colliders. That’s what I always do, anyway.
No, didn’t find a solution yet and no official answer either.
Thanks for the reply, but that won’t work on our game :? we have lots of meshes that needs to be combined and if we are going to keep the colliders for each one there won’t be a computer that could handle it.
Although having a workaround is nice, it’s better if it works as it’s supposed to.
If I understand correctly how mesh combining works, the uncombined meshes will take only a fraction of the memory compared to the combined ones.
For example, if you have 100 lamp-posts in your scene, the data to store the uncombined meshes is the size of 1 lamp post mesh (as each will link to the same mesh), whereas a combined mesh of all lamp-posts will be the size of 100x the lamp post mesh (as it includes every individual lamppost in the scene).
But perhaps my understanding of the matter is flawed.
That is correct. But then again you’ll need 100 colliders, one for each lamp-posts instead of only one collider for the combined mesh.
I don’t think that’s how it works. I don’t see why it would make 100 copies of an identical mesh.
However, if you’re right and the Physics system needs a unique copy of every mesh in every collider, you have a big problem anyway, as it would also copy your combined mesh.
I don’t know if I’m right or not but if the combined mesh is then duplicated for the physics it’s the least of my concerns because our game is running pretty well already combining meshes using the MeshCombineUtility and generating the collider for that mesh but Mesh.CombineMeshes is way faster than the script.
I have the same problem. The collision detection is not working on MeshColliders when a Mesh.CombineMeshes is assigned to the MeshCollider.sharedMesh
An official response will be appreciated.
I just ran into the same problem and then found this thread while searching for a work around. Using the CombineChildren script works fine with a MeshCollider but using Mesh.CombineMeshes does not work with a MeshCollider.
This issue is still present on Unity 3.0.0b3 (45884)
I wonder if they ever read these posts or the bug reports… It has passed more than a year without an official response.
The collision detection is not working on MeshColliders when a Mesh.CombineMeshes is assigned to the MeshCollider.sharedMesh
I’ve just reported this bug on fogbugz:
http://intra.unity3d.com/fogbugz/default.asp?365485_u30ksrpn
Let’s hope someone sees it!