Rigidbody.IsSleeping() VS Rigidbody Velocity Comparison. Performance question for object stop detection.

// 1
if (rigidbody.velocity.sqrMagnitude < stopThreshold && rigidbody.angularVelocity.sqrMagnitude < stopThreshold)
{
}

// 2
if (rigidbody.IsSleeping())
{
}

Which way is faster? The value of stopThreshold is 0.0001f, and the value of Sleep Threshold is 0.005 (Default). The value of Sleep Threshold can be changed to a higher value. I’m curious about the inner code of IsSleeping().

IsSleeping certainly is slightly faster. However it’s in the range you just shouldn’t care. IsSleeping does not perform any kind of “test” on the velocity as it just returns the inner state of the rigidbody. The Rigidbody will determine it’s sleeping state automatically. When a rigidbody falls asleep it basically deactivates the rigidbody and it’s no longer included in any physics calculations until it wakes up again.

Using a smaller threshold than the internal sleeping threshold makes no sense. If a rigidbody falls asleep it’s velocity / angularVelocity is set to 0 as from that point on the object is not moved anymore.

Of course collisions from other moving rigidbodies, applying forces or just moving the object manually will wake it up again.

ps: You usually want to use different values for the linear velocity and the angular velocity. While the sleeping threshold for the linear velocity would be different depending on your object scaling, the threshold for the angular velocity usually should be constant (as angles are not affected by scaling).