Optimize physics for query-only or non-simulating games
Prevent the default physics update loop from running to reduce unnecessary performance overhead.
Read time 2 minutesLast updated 13 days ago
Prevent the default physics update loop from running to reduce unnecessary performance overhead by changing the Simulation Mode to Script.
Preventing the default physics update loop from running can be beneficial if your game doesn't require physics simulation for the default physics scene. For example, your game might only require physics queries such as raycasts, spherecasts, or overlap checks, but not Rigidbody components with forces, gravity, or physics-driven movement.
This approach uses physics queries for collision detection or environmental interaction without the performance cost of a full physics simulation, and it maintains control over when transform data is synchronized.
Note the following if you set the Simulation Mode of the default scene to Script:
- Physics queries still function by checking against the physics world's representation of colliders.
- If you have objects in your scene that are moved by directly manipulating their components, their positions within the physics engine's internal spatial data structures are not automatically updated to match their
Transformpositions frame-to-frame (since no simulation step is occurring by default in this mode).Transform - To ensure raycasts and other queries against these colliders are accurate, assuming is
Physics.autoSyncTransforms(its default and recommended setting), you must manually callfalseonce per frame before performing your queries. This function explicitly updates the physics system with the current state of all the transform values of GameObjects that have colliders.Physics.SyncTransforms - If is set to
Physics.autoSyncTransforms, this synchronization happens implicitly before each query, but this is generally not the recommended best practice for the potential overhead of syncing before every query. Note thattrueis deprecated. To learn how to sync transforms, refer to Optimize transform value syncing.Physics.autoSyncTransforms - Without an explicit call (when
Physics.SyncTransformsisautoSyncTransforms), queries might use outdated object positions and lead to incorrect results.false
To prevent the default physics update from running in the Editor:
- Select Edit > Project Settings to open the Project Settings window.
- Select the Physics > Settings tab.
- Select the tab.GameObject
?
- Set Simulation Mode to Script.
To disable automatic simulation in script, set at runtime.
Physics.simulationMode = SimulationMode.Script;