Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  ObiRigidbody prevents Rigidbodies from sleeping
#1
Hello,

I noticed that any gameobject having an ObiRigidbody component will prevent the regular Rigidbody from sleeping.

If you create a simple cube and add an ObiRigidbody, you can see from the Ribidbody info in the inspector that it always has some amount of velocity and won't fall asleep. Disabling the ObiRigidbody component will stop the vibration and let the Rigidbody sleep. Enabling it again will resume the vibration.

I assume it can't be good for performances to have all my Obi rigids unable to sleep, and sometimes the vibration is big enough to be very noticeable.

Any reason for this, and any way to stop this behavior?

I am on Obi 6.5
Reply
#2
Hi!

Accessing the velocity property of a Unity rigidbody will keep it awake, even if you don't modify its velocity at all, or set it to zero. We reported this to Unity quite a while ago but it seems it's still an issue. See my thread in the Unity forums regarding this issue:
https://forum.unity.com/threads/rigidbod...o.1052369/

You can work around it in Obi, by checking whether the rigidbody velocity is above a threshold before assigning it. Open up ObiRigidbody.cs, and make sure its UpdateVelocities method looks like this:

Code:
        public override void UpdateVelocities(Vector3 linearDelta, Vector3 angularDelta)
        {
            // kinematic rigidbodies are passed to Obi with zero velocity, so we must ignore the new velocities calculated by the solver:
            if (Application.isPlaying && !(unityRigidbody.isKinematic || kinematicForParticles))
            {
                if (Vector3.SqrMagnitude(linearDelta) > 0.00001f || Vector3.SqrMagnitude(angularDelta) > 0.00001f) //<-New line
                {
                    unityRigidbody.velocity += linearDelta;
                    unityRigidbody.angularVelocity += angularDelta;
                }
            }
        }

That will allow rigidbodies to go to sleep.

kind regards,
Reply
#3
Super, thank you for both the explanation and the solution.

Why isn't the this new line added by default though? I am just genuinely curious.
Reply
#4
(13-04-2023, 03:52 PM)Voolg Wrote: Why isn't the this new line added by default though? I am just genuinely curious.

I have it commented out in the development branch, because I harbour the hope that at some point Unity will fix this to match PhysX's behavior.

[Image: 4830250.jpg]

But you're right I should probably just bite the bullet and check the velocity of every rigidbody every frame. That's less costly than keeping them awake, anyway.
Reply
#5
haha okay. Well yes, maybe for now it's worth adding the line then.
Reply
#6
I had a bug where some kinematic growing/shrinking doors were floating off, and somehow tracked it down to their Fluid Colliders.
So I just added some variables to disable it it on that object, and everything worked fine  Cansado
Reply