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

How change physics timeScale?

Discussion in 'Physics for ECS' started by UDN_08c892cf-fb37-48c2-920c-0e8c4758982f, Feb 15, 2020.

  1. UDN_08c892cf-fb37-48c2-920c-0e8c4758982f

    UDN_08c892cf-fb37-48c2-920c-0e8c4758982f

    Joined:
    Aug 15, 2017
    Posts:
    1
    I need change physics simulation speed, just like Time.timeScale in old unity physics.
    In this forum proposed to change Time.fixedDeltaTime, but it doesn’t help me. if I set to Time.fixedDeltaTime = 0, then the physical objects continue to move, albeit at a lower speed.
     
  2. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    349
    I would like to know this as well. Fixed time step should not control the speed of simulation, that doesn't make sense. Either I missed an important piece of configuration or this is an embarrassing bug on Unity's side.
     
  3. apaxnid

    apaxnid

    Joined:
    Nov 18, 2012
    Posts:
    34
    this is from StepPhysicsWorld.cs
    Code (CSharp):
    1.  
    2. #if !UNITY_DOTSPLAYER
    3.             float timeStep = UnityEngine.Time.fixedDeltaTime;
    4. #else
    5.             float timeStep = Time.DeltaTime;
    6. #endif
    You can make hacks like changing Time.fixedDeltaTime before stepphysicsworld and reverse it to normal after. You can even change simulation type to NoPhysics if you don't want to step physics simulation this frame. Or you can edit ComponentSystemGroup.cs and make SetFixedTimeStep method public and then in custom world bootstrap set SimulationSystemGroup's fixed time step. Or you can wait. Unity will figure out proper API soon™ enough:)
     
    phobos2077 likes this.