[ON HOLD] Improved Sleep System: Enhancing Accuracy, Consistency, and Performance

The sleep system is responsible for determining which assemblies should be simulated during each physics simulation step. If an assembly is moving very slowly and has no net forces acting on it, it is put to sleep and removed from the simulation, thereby improving performance. When a large enough force is applied to the assembly, it is woken up and simulated. All of this is handled automatically by the engine, requiring no effort from developers to achieve optimal performance.

Creating a system that handles this automatically is a considerable challenge, and a variety of issues have been identified with the help of our awesome developer community:

Many of these issues are a result of inconsistencies with how we determine if an assembly is moving or about to move. As a result, we’ve reworked the sleep system to both resolve these inconsistencies and deliver improved performance.

What is the change and who will it impact?

A few changes to the sleep system were made to resolve these issues:

  • A more accurate check on the change in orientation to check if an assembly is rotating. This should prevent rotating objects from going to sleep prematurely and allow objects that are rotating very slowly to correctly fall asleep.
  • Improved treatment of sleep-checking assemblies (sleeping assemblies that share a constraint with an awake assembly). By integrating the sleeping constraint forces, sleep-checking assemblies now fall asleep and wake when they should.

The images below illustrate these improvements on a long bridge of parts connected with hinge constraints. The existing sleep system, shown on the left, fails to put the bridge fully to sleep. When the improved sleep system is enabled, the bridge quickly falls asleep after the initial transient motion.

Legend
No Outline = Asleep
Red Outline = Awake
Orange Outline = Sleep-Checking
Purple Outline = Not yet simulating

Old Sleep System
Old Sleep System Logic
New
New Sleep System Logic

With the existing sleep system, shown on the left, mechanisms with large constraint forces sometimes jitter as individual assemblies rapidly fall asleep and wake back up. With the new sleep system logic, these mechanisms smoothly and fully fall asleep, as shown in the right-hand image.

Old Sleep System - Jittering
Old Sleep System Logic
New Sleep System - Smooth
New Sleep System Logic

A complex locomotive fails to fall asleep with the old sleep system. When the improved sleep system is enabled, all 44 assemblies fall asleep within a few seconds.

Old Sleep System - Locomotive Awake
Old Sleep System Logic
New Sleep System - Locomotive Asleep
New Sleep System Logic

While this change potentially affects any simulated mechanism with low velocity assemblies, we believe that the vast majority of mechanisms will continue to operate as they do today.

Why should you care?

These changes fix a number of issues with the sleep system but there is the potential that they could break things for your players. To avoid any impact, you should verify that any mechanism in your experience works as intended with the improvements enabled. If not, it will need to be updated before the rollout ends.

Phased rollout details:

During the rollout, you will be able to control if the improved sleep system is enabled in your experience through the new Workspace property PhysicsImprovedSleep with the options: Default, Enabled, and Disabled.

This phased rollout is intended to help you test whether these changes affect any of your existing mechanisms. You can do so by setting the PhysicsImprovedSleep property to Enabled during the first phase and then testing your mechanisms.

This phased rollout will also provide a buffer to creators who may miss this announcement and experience breaking changes once we go to the second phase and Default then maps to Enabled — switching the PhysicsImprovedSleep property to Disabled during the second phase will provide a buffer for fixing any broken mechanisms prior to us applying these changes unconditionally.

Identifying and addressing issues:

The sleep system uses a number of thresholds to determine if an assembly is moving or accelerating. Anything moving and accelerating below these thresholds will be put to sleep. The thresholds are summarized in the table below.

Threshold State Change Value
Linear Velocity Awake ↔ Sleeping 0.33 studs/s
Rotational Velocity Awake ↔ Sleeping 0.42 studs/s
Linear Acceleration Awake ↔ Sleeping 0.24 studs/s2
Rotational Acceleration Awake ↔ Sleeping 0.24 studs/s2
Neighbor Linear Velocity Sleep-checking ↔ Awake 0.48 studs/s
Neighbor Rotational Velocity Sleep-checking ↔ Awake 0.48 studs/s
Wake Linear Acceleration Sleep-checking ↔ Awake 16.9 studs/s2
Wake Rotational Acceleration Sleep-checking ↔ Awake 16.9 studs/s2
  • The rotational thresholds reflect the velocity and acceleration of a point located on the assembly bounding sphere (a sphere that contains all of the parts in an assembly) that moves rigidly with the assembly. This ensures that a very large assembly that is rotating slowly won’t go to sleep when points far from the center of rotation are moving rapidly. The image below shows parts of three different sizes rotating at three different angular velocities. Increasing the size or angular velocity of a part prevents it from sleeping.

image3

  • If an awake assembly is moving above the Neighbor Velocity thresholds, it will wake any sleep-checking assemblies connected to it via constraints.
  • A sleep-checking assembly will accelerate if the net body and constraint forces are no longer in equilibrium. If the computed acceleration of a sleep-checking assembly is above the Wake Acceleration threshold, it will wake.

The improvements to the sleep system may slightly change how your mechanisms fall asleep and wake. Depending on the type of constraints that are used in your mechanism, there are number of constraint properties you can change to ensure your assemblies don’t fall asleep prematurely:

  • For Mover Constraints, try increasing
    • Responsiveness
    • MaxForce/MaxTorque
    • MaxVelocity/MaxAngularVelocity
  • For Mechanical Constraints with ActuatorType set to Motor, try increasing
    • MotorMaxForce/MotorMaxTorque
    • AngularVelocity
    • MotorMaxAcceleration
  • For Mechanical Constraints with ActuatorType set to Servo, try increasing
    • LinearResponsiveness/AngularResponsiveness
    • ServoMaxForce/ServoMaxTorque
    • Speed/AngularSpeed

Alternatively, you can reduce the density of your parts so that any constraint forces acting on them result in faster motion.

We anticipate that most mechanisms will continue functioning correctly without any modifications. To help you diagnose any unexpected behavior, you can visualize which parts are awake and asleep.

Please report any issues you encounter in this thread, including cases where mechanisms fail to sleep when expected or fall asleep when they shouldn’t. Your feedback is crucial for us to continue refining this powerful system.

As always, please let us know if you have any questions or concerns!

Best,

Roblox Physics Team

136 Likes

This topic was automatically opened after 10 minutes.

this is a really great improvement…
im glad this has been added, finally no more jittery parts and counting what seems like unmoving and unanchored objects as still “alive”

7 Likes

Does this mean we can sleep from now on for a longer period of time?
:slight_smile:

(pun intended)

9 Likes

Very good news! Could we possibly also get an option to force keep parts awake? Have had issues with weird hacky methods when designing stuff like physically driven doorbells.

28 Likes

Roblox been pumping out updates today. Guess they weren’t over their monthly quota. This is wonderful though, no more jittering in dead rails (i think that is the case if I am reading this right) and shaky cars

1 Like

Have the thresholds for waking an object up been increased or are those the same thresholds as before this update?

:o tysm!! I really hope this solves the issue I’ve been having!

1 Like

Fully agree, no matter what changes are made, we need a way to force no-sleep on parts. Way too many games, especially realistic physics simulations and other uses of slow-moving or slow-accelerating parts will require this. This will result in vehicles being jerky when starting to move from being stationary as they wont start moving until their forces become “significant” regardless of our existing smoothing for their acceleration.

9 Likes

This is great, but when are we gonna get physics that doesn’t clip through objects? I’d love to be able to set specific objects to run higher detailed physics so they don’t clip through.

2 Likes

Thank you so much for being transparent on the constants used for the thresholds between sleeping and waking assemblies. I know people have asked for an API to dictate whether an assembly should be forcefully-kept awake, but imo this is even better—keeping parts from falling asleep, without causing weird engine quirks & edge-cases to consider.
And the in-depth information is the cherry on top of it all! Developers had to guess & experiment around to figure such behavior out before this. :heart_hands:

2 Likes

Would also be nice if we could keep client sided parts awake even when they are out side the bounds of content streaming

18 Likes

+1. Need this for all client simulated parts, network owned or locally created

3 Likes

please add a toggle for allowing the part to sleep.

8 Likes

to be truly completed this requires an ability to keep parts awake and lower the thresholds for putting them to sleep

3 Likes

Nice update, but will that affect player characters?

Making improvements and fixes is cool, but it’s really weird how roblox refuses to provide manual control for a lot of things to developers.
Why are these sleep thresholds not adjustable? There should at least be a way to force parts to be awake or go to sleep via code.
Stuff like that might be extremely useful in some niche scenarios, for example an extremely slowly moving part or optimization by instantly putting to sleep lots of unused parts.

Same goes for streaming, pathfinding, and perhaps some other systems.
Manual control over network ownership is one area where control has been given, thankfully, and it’s amazing.

7 Likes

Agreed.
We need methods like Runservice:Sleep(Part:BasePart) and Runservice:Awake:(Part:BasePart)!
I could make a feature requests, but i don’t have permission to do so

5 Likes

Are these improvements only disabled in production, or are they also disabled in the studio?

as far as i know player characters always simulate their physics