I’m seeing 4.5ms spent on Physics.Interpolation, 3.7ms of which is going to Physics.SyncColliderTransform on any given frame. This happens to GameObjects (“Vehicle Holder” in below image) which contain a single capsule collider. Rigidbody components get added and removed every N (3-30) seconds for 2 seconds then removed. The “Vehicle Holder” GOs have children with mesh, their own compound colliders, LODs, etc. Each of these 50 or so GOs are a child of a single parent (“Path - Spadina South” in below image). The parent performs a transform.translate. I assume this is where the CPU cost is coming in since, presumably, even if the Vehicle Holder GOs don’t move within the parent it still needs to recalculate its physics position in the physics engine (I could be wrong about this).
Is there a better approach to this, or perhaps something simple I can do to alleviate the pressure? I thought about using physics instead of translating the parent, but I’m not sure that’d help.
I’m trying to understand your issue. Out of curiosity why are you added and removing Rigidbodies so often?
A couple of things to check…
Do you have the AutoSyncTransforms unchecked in the Physics section of the preferences? This can reduce CPU significantly.
Also, make sure that you don’t have gameObjects in heiarchy moving when possible…that can also cause Physics.SyncColliderTransform to be high. What I do is unparent game objects that need to move or rotate when the game starts, to prevent this.
I’ve gone back and forth on the AutoSyncTransforms option over the last few months. Recently it is not enabled.
I do have gameobjects that are children that move. Well, it’s the parent that moves, with about 50 or so children (cars). The child cars all need to move at the same speed and direction, so I figured it would be more performant to have them as children and calculate the transform.translate only once on the parent, rather than 50 times in Update(), which would be required if the cars are at the root instead of as children. In actuality, it’s 50 cars per road, and about 20 roads - so about 1,000 cars (although 90% are disabled at any given time).
With regards to the adding/removing of Rigidbodies… My vehicles don’t have Rigidbodies by default as any colliders that trigger an action already have rigidbodies on those. However, as a car takes a turn at an intersection, I add a rb so that it can detect any imminent collisions with other cars. Once it has settled into the lane the rb is then removed, since there’s no way to disable Rigidbodies. I’m working under the assumption that moving a GO using its transform while a rb component is attached is less performant (even with isKinematic) than without a rb component. I haven’t run large-scale tests to confirm this hypothesis though.