Not A Bug The Top Menu freezes physics weird

via5

Well-known member
Messages
132
Reactions
389
Points
63
This is not a new problem with 1.20.77.2.

Add the attached script to a Person atom. There's a force on the X axis that's applied to the Person's head, moving it to their right.

Then, click the "Open Top Menu" button (star icon), wait a few seconds, then click "Return To Scene View". The Person's head will jerk violently and then move back to its initial position. I suspect something in the physics simulation is frozen while the menu is opened, which makes Unity add the forces applied to a rigidbody instead of resetting them on each frame.

Now, the top menu also sets `freezeAnimation`, which any good plugin should honour, but my Synergy plugin allows for freezing the model in place instead of resetting the forces to 0. This normally works fine, but not while in the top menu.

The "CycleForce" atom does not seem to have this problem at all, so I might be missing something obvious.
 

Attachments

  • FreezeTest.cs
    352 bytes · Views: 0
CycleForce obeys freezeAnimation.

You need code to not apply forces in FixedUpdate while freezeAnimation is set:

Code:
    public void FixedUpdate()
    {
        if (SuperController.singleton == null || !SuperController.singleton.freezeAnimation) {
            head.AddRelativeForce(100, 0, 0);
        }
    }

Opening the top menu does something additional that regular Freeze Motion/Sound does not. It sets Physics.autoSimulation to false, which prevents the physics engine from simulation. FixedUpdate is still called however. So when you open the top menu, physics simulation is stopped, and your script keeps adding force to the head. When autoSimulation is turned back on those forces have accumulated and then apply all at once. If you obey freezeAnimation, however, you won't have this issue. You could also check to see if Physics.autoSimulation is set to true and only apply forces if that is true.
 
My problem is that I use the `freezeAnimation` flag as a way to freeze whatever forces are applied. I don't want to reset them. It works fine everywhere except for the top menu, as far as I can tell. I do have an option in Synergy to stop applying forces on freeze, but I never use it. Things just snap back in place, limbs become entangled and things explode spectacularly.

But `Physics.autoSimulation` is what I was looking for, I can work with that.
 
Back
Top Bottom