Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Quick clarification on fixedDeltaTime

Discussion in 'Scripting' started by Marscaleb, Sep 13, 2020.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,036
    If I'm writing code in the FixedUpdate function and I use time.deltaTime, is the value I get from that going to be whatever the last deltaTime was from the last time Update was run?
    Or will it be context sensitive and give me the time since the last fixedUpdate, effectively giving me the same result as Time.FixedDeltaTime?
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    IIRC Unity has some special logic that causes Time.deltaTime to always return the value of Time.fixedDeltaTime if you access it during FixedUpdate.

    Shouldn't be hard to test if you need to be sure.
     
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,036
    Uhg, I shouldn't try to write code this late at night, and missing crap like this is exactly why.

    Yeah, I just tested it, and I can even have a separate function to read the value of deltaTime so both update and fixed update are calling the exact same code, and fixedupdate sill gets the time since the last fixed update and update still gets the time since the last update.

    ...I should go to bed and debug this thing when I'm more alert.