Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Physics scheduling bug? Massive drop in performance setting PhysicMass

Discussion in 'Physics for ECS' started by thelebaron, Aug 16, 2022.

  1. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Resolved - didnt realize I had an extra PhysicsStep. Maybe this should error out unless I'm missing the need for multiple of these

    Getting a huge drop in performance when setting the mass for rigidbody ragdolls. Above profiler is prior to ragdolling(kinematic) and below after(non kinematic). Note that this profiler picture is from about 14 constrained body pairs(/joints). Its an extremely low amount of physics entities in the scene at the time of the performance drop.

    A very simplified rundown of what happens is:
    When health is zero, a character entity sets all of it's rigidbody entities to a non kinematic PhysicsMass. When that happens, drop in performance.

    The ParallelCreateContactsJob appears to be the culprit, its a minuscule amount prior to the "switch" and then appears to go into some sort of single threaded stall.
    This happens with both havok and unity physics.
    Also note that if all the ragdoll physics entities(colliders+joints) are destroyed, this stall will continue to occur with the below profiler for a good 10-20 seconds, before it finally settles down.

    Now I have a prior project commit a day ago where this all works without any hitches/slowdowns and obviously somewhere along the way I added something that causes this, but the code introduced does not touch any physics or FixedStepSimulationGroup whatsoever. My only conclusion at this point is there's some sort of scheduling error?

    Unity_7obtjmVrsj.png
     
    Last edited: Aug 16, 2022