|
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.
(comments are locked)
|
|
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. Thanks for your reply. I do have some experience with other physics engines and i know what benefits the primitive colliders have, but let's say i have to use mesh collider and my mesh is already convex. But unity is checking and recalculating a convex mesh for every single instance of prefab, which is very laggy. Is that really necessary? (runtime performace is good since mesh to mesh pairs/collisions are rare)
Aug 08 '12 at 02:41 PM
Pangamini
It seems that the generated mesh is not shared. There might be a design explanation, but this is beyond my skills and knowledge of Unity Try to ask the Unity support. Maybe this will change in the future. Ideally, it would be great to be able to flag a mesh as being convex so that recomputation is not necessary.
Aug 08 '12 at 02:51 PM
Kryptos
There's a flag "generate colliders" in the importer, but i don't see any performance boost
Aug 08 '12 at 02:57 PM
Pangamini
(comments are locked)
|
