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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

TimeStep = 0 does not pause Unity Physics simulation (manually stepping physics)

Discussion in 'Physics for ECS' started by gtzpower, Jun 22, 2022.

  1. gtzpower

    gtzpower

    Joined:
    Jan 23, 2011
    Posts:
    315
    We manually step physics for our product, and one thing I have noticed is that setting the TimeStep = 0 does not fully stop the simulation. Things still move, but much slower.

    Here is a snippet of code showing how we step the simulation:
    Code (CSharp):
    1. using Unity.Entities;
    2. using UnityEngine;
    3. using UnityEngine.Events;
    4.  
    5. [DefaultExecutionOrder(-32000)]
    6. public class PhysicsTick : MonoBehaviour
    7. {
    8.     public UnityEvent<float> OnBeforeStepEcsPhysics;
    9.  
    10.     private FixedStepSimulationSystemGroup fixedStepSimulationSystemGroup;
    11.     protected void Start()
    12.     {
    13.         fixedStepSimulationSystemGroup = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<FixedStepSimulationSystemGroup>();
    14.         fixedStepSimulationSystemGroup.Enabled = false;
    15.         fixedStepSimulationSystemGroup.RateManager = new RateUtils.FixedRateSimpleManager(0);
    16.     }
    17.  
    18.     protected void Update()
    19.     {
    20.         fixedStepSimulationSystemGroup.Timestep = 0;
    21.         fixedStepSimulationSystemGroup.Enabled = true;
    22.         fixedStepSimulationSystemGroup.Update();
    23.         fixedStepSimulationSystemGroup.Enabled = false;
    24.     }
    25. }
    26.  
    You can put this MonoBehaviour onto a game object in the ApplyImpulse physics sample, and when you play, you will notice that the objects are still moving/simulating, just very slowly. Is there any way to get the simulation to completely pause with TimeStep alone or will we need to just disable the StepPhysicsWorld system?