Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    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:
    31
    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:
    229
    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.
     
    Hsgngr likes this.
  3. Hsgngr

    Hsgngr

    Joined:
    Dec 28, 2015
    Posts:
    31
    Thanks
     
unityunity