I have noticed that creating a complex convex mesh collider produces a significant lag, even if i am instancing the same prefab with the collider multiple times. It looks like the concave->convex procedure is called for every instance. My question is if it's possible to pre-build(runtime) or bake(in editor) a convex mesh for mesh colliders so it doesn't have to be generated every time a collider is instanced.
asked Aug 08 '12 at 01:09 PM
The best solution would be to NOT use any MeshCollider. The computation of the convex collider (convex hull closure) can be very expensive. And the resulting collider will also be very expensive.
My advice: create a compound collider with the primitive colliders (Box, Sphere, Capsule) and make a prefab with it. This will take a little more time during editiong, but will have much greater performance at runtime.
A quick (and also not 100% perfect) explanation to why MeshCollider are so expensive.
First, let's explain why the primitive collider are so cheap.
Therefore, the order of collider is (cheapest first): Box < Sphere < Capsule.
Now a MeshCollider is just a bunch of triangles. The engine has to check each triangles against collision. Thus: MeshCollider >> Capsule.
With a convex collider, there are some optimizations (not presented here). But basically in the worst case, the physics engine still has to check each triangle.