We are working on our first iPhone game using Unity and have hit some nasty performance issues.
We have a ragdoll character that falls down a hill, bouncing off of other objects as he goes. Things work fine, but performance is bad. We never get above 15fps, and usually hover between 7 and 10fps.
It is looking like Physics is our big bottleneck. Here is a typical set of profile data:
The objects in the world are mostly sphere and box colliders, however the terrain is a MeshCollider.
Any ideas what could be killing our performance?
What kind of performance should we even be expecting?
Would it help to activate objects as they came into view, and deactivate them when they left, or doesn’t PhysX care?
Would there be a performance difference between Unit Indy and Advanced? We are currently using Indy.
You likely overdid your setup.
Don’t forget, its a phone, not a “slow pc”
Back in 2002 (when comparable pcs were available) nobody would have come up with the idea of heavier physical simulation.
1st thing I’ve noticed looking at your profile stats is that skinning takes 20ms. I assume you’re using 4 bone weights per vertex?
With Unity iPhone 1.1 you will get a significant performance boost with skinning. Meanwhile reduce your bone weight count to 1 on skinned mesh - that will save you some performance.
MeshColliders are expensive, even extremely expensive if you combine them with ragdolls.
I would guess that MeshCollider is your main performance bottleneck. You have to either significantly reduce amount of polygons on your MeshCollider or ditch it altogether and use bunch of primitive colliders instead. Btw, if your MeshCollider geometry is convex, do not forget to set convex flag on a collider.
How many MeshColliders and primitive colliders do you have in your scene?
I have our ragdoll set to 1 bone. (that is the quality setting in Skinned Mesh Renderer, right?)
Oh you taunt me, but when will it be releases?!?!
Total Mesh Colliders: 19, with 7680 triangles total
Total Primitive Colliders: 531
Yes, looking at those numbers, I can guess it is too much.
Even when I strip out all the mesh colliders and primitive colliders (except a simple box collider), I’m still only getting around 14fps average.
Would it be useful to dynamically enable/disable the primitive colliders as the character moves through the scene? Would the overhead of activating/destroying objects outweigh any gains?
you have 5000 poly+ too much on the mesh collider and a few hundred primitive coliders more active than you should have.
remember, its a phone, not a pc.
what also is impacting your performance is the amount of objects you have. I doubt you stay below 12’000 static polygons if the mesh collider already is using up half of it.
would guess that some kind of occlusion culling or manual system that does something similar will really help your situation.