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. Dismiss Notice

Is there a Physics.sleepThreshold equivalent

Discussion in 'Physics Previews' started by duzbot, Feb 21, 2020.

  1. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    for the new physics unity system? I can't find anything else on this

    May I add that I'm trying to get rid of jitteriness in a pile of entites with physics shapes & bodies
     
  2. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    There's no states on the Unity Physics, meaning there isn't sleep states either.
     
  3. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    I'm not sure what it would have to do with states.
    I imagine the way you would achieve this effect is to have a system that checks an entity's velocity is below a certain 'sleep threshold' and to remove/set its physics body component.
    I was wondering if there was already something that basically does that
     
  4. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    You can't just sleep object the moment it's velocity is near zero, it can do that momentarily while changing direction too.
     
  5. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    That's true - although I think the rationale still stands. How would you go about achieving the desired effect i outlined?
    What about checking if an entity has not recieved a force greater than a threshold for a certain amount of consecutive frames?
     
  6. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I'd imagine one could just have some float that tracks how long the object has been under some velocity threshold and once some time threshold is reached, it would get sleep tag component which would omit it from rigidbody simulation itself.

    But you can't get huge gains from this though as you can't optimize the actually taxing part of physics sim which is the broadphase, you still need to keep tracking the slept rigidbodies there and can't group them in bigger boundaries to reduce the perf hit (like done in physics engines normally) without major rework.

    All in all, I feel that sleeping isn't implemented because the parts that are trivial to implement for it will not give you notable perf gains + all quick hacks still go against the idea of the physics engine being stateless.
     
  7. duzbot

    duzbot

    Joined:
    Aug 31, 2017
    Posts:
    17
    Ok, thanks.
    I didn't really consider this for performance gains. I was getting undesirable visual effect of 100s of rigidbodys jittering whilst being in close proximity/touching eachother (their colliders dont appear to be overlapping) How i understand it is that the rigidbodies are perptually sending impulses to eachother. Is this something that will get ironed as the new physics gets refined?
     
  8. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Not being able to stack a ton of rigidbodies is a known limitation of Unity Physics, you can use Havok Physics to overcome this.
     
    duzbot likes this.