Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Timer in the fixedUpdate or Update in order to get stable timer ?

Discussion in 'ML-Agents' started by Hsgngr, Jun 26, 2020.

  1. Hsgngr

    Hsgngr

    Joined:
    Dec 28, 2015
    Posts:
    61
    I need a Timer countdown. Where should I decrement this variable, on FixedUpdate or Update ? I know while training, Time Scale can be 20 times faster so I need to know what is the correct way to do this. Thanks

    Code (CSharp):
    1.  if(Status == INFECTED)
    2.         {
    3.             if(recoverTime <= 0f)
    4.             {
    5.                 Status = RECOVERED;
    6.             }
    7.             else
    8.             {
    9.                 recoverTime -= Time.deltaTime;
    10.             }
    11.         }
     
    Last edited: Jun 26, 2020
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    Both Time.deltaTime and Time.fixedDeltaTime are affected by timeScale. Therefore you can decrement in Update (Time.deltaTime) as well as in FixedUpdate (Time.fixedDeltaTime). The agent loop runs on FixedUpdate steps, so FixedUpdate should the better choice if you need to sync value changes with agent steps.
     
  3. Hsgngr

    Hsgngr

    Joined:
    Dec 28, 2015
    Posts:
    61
    Thanks