Control the physics simulation manually to decide when physics calculations occur to align physics updates with your application’s actual performance and avoid redundant updates. This can help optimize performance during busy frames and is beneficial for scenarios that require tight synchronization with game logic or custom physics update loops.
Manually control the physics simulation to:
Time.deltaTime
, can cause unstable simulations, and lead to issues such as objects passing through each other, a phenomenon known as tunneling, at low frame rates or jittery behavior when frame rates fluctuate.Time.deltaTime
increases. Simulating a physics step with a large, variable delta can be computationally resource intensive and less accurate, potentially worsening performance issues.Use Physics.Simulate(float stepTime)
(or yourPhysicsScene.Simulate(float stepTime)
) to manually control the physics simulation and in specific, local PhysicsScene
instances. Refer to the Multi-Scene Physics learn tutorial to learn more about multi-scene physics.
When you call Physics.Simulate
, the recommended best practice is to use a fixed time step, rather than directly passing Time.deltaTime
. For example, use the same value that you might use in the Project SettingsA broad collection of settings which allow you to configure how Physics, Audio, Networking, Graphics, Input and many other areas of your project behave. More info
See in Glossary’ Fixed TimestepA customizable frame-rate-independent interval that dictates when physics calculations and FixedUpdate() events are performed. More info
See in Glossary value, such as 0.02 for 50Hz.
If you manually simulate physics in a sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary using Physics.Simulate()
, ensure that automatic simulation is disabled. You can do this by setting the Simulation Mode to Script. Once in Script mode (either through Project Settings or script), you must call Physics.Simulate
for the scene at a selected frequency with an appropriate, preferably fixed, time step.
To disable automatic simulation, in the Editor:
To disable automatic simulation, in script, set Physics.simulationMode = SimulationMode.Script;
. Typically, you do this at the start of your game, before any physics simulation occurs.