Quite simply, which one is more expensive?
I have a scene with about 10000 static colliders, they can approximately be boxes or capsules so its not too much of an issue which one I choose. Though I haven’t thoroughly profiled it, comparing the two, my eyes seemed to tell me that capsule colliders were performing quicker but logically i think boxes should be quicker.
Well I decided to post some results from some testing.
All tests were done on an intel core2duo 3ghz imac with no rendering, just physics.
Static colliders seem to have such a minimal impact on performance, Upto 60,000 and beyond of all different colliders were causing no noticable effect on the frame time (<3ms)
So I tried testing dynamic colliders instead, much more challenging.
Remember this is just physics, your renderer would bottleneck way before reaching 2500 individual objects.
People who would expect the boxes to be faster aren’t considering the possibility that the boxes are rotated, I imagine.
I’m curious - is it faster if all of the boxes have fixed rotation, or does Unity not recognize that / have some way of being told that so it optimizes accordingly?
I guess I’m just being silly. Premature optimization is the root of all evil, and it’s easy enough to swap between the different colliders later on.
wow this is what im looking for
i plan to change all my chars from box collider to capsule, but afraid of the impact on performance
turn out that capsule is better than box
You will find much greater performance hits from the actual physics and collisions. If things aren’t touching, you can have far more. If some things are sleeping, you can have far more. Your fixed update rate affects performance, and layers are important for performance. It’s not just about which collider might be a tiny bit quicker.
While choosing a collider is important, bigger gains are obtained from what you do with them.
But that doesn’t mean he isn’t right. I have 500 + colliders on my scene, and since its a 2.5D side scroller, a lot of collisions are happening to tell the objects to do different things depending on where they are relative to the camera. So this info is really useful. Any little inch you can get when you deploy for mobile, is important.
well, yes. But any primitive collider, you’ll be finding that if its playable or not comes down to layers and what you’re doing with them… if its mesh collider then it’s a different story, those things are quite slow
It is still useful fundamental information, no need to shoot the posters down for it.
That said, hippocoder does have a point. Also, capsules might be more efficient, but generally take much longer to stabilize as they will tend to roll, whereas a box will stop moving once the bounce has settled and go to sleep. Physics might be cheaper but they will calculate for a longer time in many cases.