Performance Question on Kinematic Rigidbodies

Hello everyone, I’ve been doing some on device testing (in my case an iPhone 4) using the free Unity profiler and default Unity physics settings, and noticed that in a particular scene physx is taking around 40-60ms to render about 30-40 objects that are kinematic rigidbodies controlled through scripts (use no real physics).

More details:
-The scene in question is a “frogger” type setup, where rocks move along a straight path and bob up and down (all according to script), and when a player stands on them, they begin to sink.

Each rock has a mesh collider and a mesh trigger.

The primary script methods used to move these rocks are Vector3.Slerp, Vector3.MoveTowards, and Vector3.Distance.

I have been reading around and apparently for the number of objects on screen, this is a very significant amount of time spend on physx. So, I was wondering what the best to way go about cleaning this up is? Changing physics settings? Different object setup? Different script methods? Any help is appreciated.

I should also mention that at this point, for convenience these rocks are instantiated and destroyed (not recycled) and the garbage collector tops out at around 5.

Just a point of detail - PhysX doesn't do rendering. It's solely for physics calculations. Rendering is done separately. But, as has been said, it's MeshColliders that are causing the problem - they are very expensive. It's best, where at all possible, to approximate them by one or more primitive colliders.

–

1 Answer

1

Mesh colliders are very expensive for performance. So, this where I would start. Try to approximate the rock shape with another collider, e.g. capsule.

Also, you should really use some pooling method to recycle the rocks, because the GC kicking in at any point in the game, could make the game freeze for a couple of seconds or so.

Fair enough, I made some adjustments earlier today: -Removing the mesh trigger and using on Collision instead of ontrigger saved about 50% performance vs the old setup -Changed fixed timestamp from 0.02 to 0.04 and that also saved about 50% performance vs the old setup So really, just those 2 changed together probably would be enough, but I'll work on pooling next. By the way, does the GC cause freezes even if the profiler is showing minimal GC times?

–

The GC will cause freezes even when the profiler shows minimal GC times. Because the GC is ran whenever it feels like it needs to, and when it does, you will see the framerate drop.

–

I see, thanks.

–