Is it better to use the Plane Mesh Collider or a Box Collider for Walls and Floors.
I noticed that the Plane has a Mesh Collider and the Cube has a Box Collider. I'm wondering if a simple Plane type Mesh Collide would be as efficient or more efficient than a Box Collider for floors and one sided walls? Does anybody know?
Answer by FortisVenaliter · Jul 17, 2017 at 07:41 PM
A box collider is calculated as a collision volume, whereas mesh colliders check their bounds first, then run a per-triangle collision (on reduced triangle meshes generated by the engine, but still). So, typically, it's better to do the box colliders.
However, if you're doing a whole level, one mesh collider is probably better than a hundred box colliders, so it's a give and take.
Ok, maybe I should ask this another way. Why do they use a $$anonymous$$esh Collider on a plane ins$$anonymous$$d of a very thins box collider?
Two reasons. One, a very thin box often ends up causing problems due to how thin it is, which could produce unexpected effects. Two, a mesh collider is normal-dependent, meaning it ignores backfaces as well, which a box collider would not. In short, a mesh collider is more appropriate.
I usually use box colliders with a thickness of at least 0.5 for ground colliders.
Well summarised. Though i'd like to add that a normal $$anonymous$$eshCollider does not reduce the triangles at all. Only when you select "convex" Unity tries to calculate the convex hull of the mesh (which btw isn't always possible since the convex hull is limited to 256 triangles).
Normal $$anonymous$$eshCollider also allow you to actually deter$$anonymous$$e which triangle was hit when raycasting.
Great points; definitely something to consider.
FortisVenaliter: $$anonymous$$aybe I am a little dense, but it seems lie you said that a $$anonymous$$esh Collider would be appropriate for a floor or one sided wall, but you use a Box Collider of >.5 thickness. What am I missing?
I'm just wondering what the cost is for a simple $$anonymous$$esh Collider that is flat and made up of two triangles. I sort of think that since Unity uses a $$anonymous$$esh Collider for a plane that it is more efficient than box in this case, but that may not be true.
But if it is true, might it also be true that if you have a wall that has a thickness of say .1, and nothing would ever come in contact with the ends, top, or bottom, that two $$anonymous$$esh Colliders would be better than one Box?
It's certainly possible. The best way to tell would be to run it both ways and check the profiler. With the complexity of modern game engines, there are few hard and fast rules, more of just guidelines you pick up with experience.
I think the disconnect is with one simple fact: The mesh collider uses triangle-based collisions, whereas the other pre-built colliders use volume-based collisions.
That means that the shape colliders never have to test against individual triangles, whereas a mesh collider will always have to loop through the triangles if there is a collision. That's what makes them inherently faster. So, if your mesh collider has fewer triangles than the total number of shape colliders, yes, it can absolutely be faster.