- Home /
Using MeshCollider with Quads
I am running into issues with the Quad mesh option playing nice with older functionality. I have gotten past most of the issues, but this one has me stuck and my work around seems an inefficient way of handling colliders.
When you generate a mesh using MeshTopology.Quads and then add a MeshCollider component, Unity throws an error. It complains that the collider can not construct a mesh from the non-triangle data. Is there any way to overcome this issue? I would like to support both Quads and Triangles in my plugin that I am building...
It seems like the only way to work around this issue is to add the MeshCollider before the mesh data is even created. Then update it's shared mesh with a new mesh object, thus getting no warnings. This works fine when you are not providing an existing mesh a new collider, but in my case I am streaming in objects and building colliders on the fly as you get closer to them. Since these are quad meshes, I am getting errors which halt the collider generation.
Is there any workaround? Can I build a stand alone MeshCollider Object and then attach it to a gameobject? I tried using the built in AddComponent but I don't think that is possible.
Thanks so much!
Answer by DaneC020 · Dec 28, 2012 at 09:31 PM
I have found a work around for now, but would love to know if there is a better way to handle this issue.
//After creating the Quad mesh, setup Triangles for collider info.
mesh.sharedMesh.SetTriangles(mesh.sharedMesh.GetTriangles(0), 0);
This satisfy the MeshCollider, but wonder if it is causing any overhead?
Thanks