- Home /
Get actual Time.deltaTime from FixedUpdate()
Hi!
I know that reading Time.deltaTime and Time.time from FixedUpdate() does return the values for fixedDeltaTime and fixedTime instead of the actual ones, but I would like to read the actual deltaTime and time. I need to do it as early as possible during the frame, which by my knowledge is FixedUpdate().
Is there some other way to read the actual deltaTime and time from FixedUpdate()?
Is there some other per-frame event that executes before FixedUpdate() from which I can read the actual deltaTime and time? I wish there was an EarlyUpdate event in which we could do per-frame preprocessing stuff.
The reason why I want to do this is because I need to predict the number of times FixedUpdate() will be called per frame, in order to do some interpolation of physics related network data over the FixedUpdate calls.
Where did you hear that
reading Time.deltaTime and Time.time from FixedUpdate() does return the values for fixedDeltaTime and fixedTime instead of the actual ones
I think it still does return the time it takes for a frame to complete and not fixedDeltaTime, or else that would defeat the point of having a separate property. Also, how would it know it's being accessed from within a specific function?
From the documentation, and confirmed through testing:
When this is called from inside MonoBehaviour.FixedUpdate, it returns Time.fixedDeltaTime.
https://docs.unity3d.com/ScriptReference/Time-deltaTime.html
I agree that it somewhat defeats the purpose with the separate properties.
You could do Time.deltaTime / Time.fixedDeltaTime
in Update. Also they are both 'actual ones' because Update is called every frame and FixedUpdate is called every physics frame, delta time is the amount of time elapsed since the last frame.
Unfortunately the thing I need it for cannot wait until Update(). Need to access it earlier, either before or during the first FixedUpdate() of the frame.
Yes, but I would say that the "actual", or "main", meaning of the property Time.deltaTime is the elapsed time since last frame, as the documentation says, and the fact that it returns fixedDeltaTime during FixedUpdate() is just a special case, even though there already is a separate property called Time.fixedDeltaTime for that.
I guess they could introduce a "Time.elapsedSinceLastFrame" property for this that isn't context dependent.
Can you use Time.deltaTime from Update in previous frame instead?
I believe you're familiar with the order of execution for event functions and it doesn't look like Unity can access Time.deltaTime for the frame from FixedUpdate due to this exact frame is not yet rendered.
FixedUpdate is often called more frequently than Update. It can be called multiple times per frame, if the frame rate is low and it may not be called between frames at all if the frame rate is high.
Your answer
Follow this Question
Related Questions
Slow update best practice 0 Answers
difference with Time.time, Time.deltatime, Time.frameCount 3 Answers
Can I use Stopwatch without syncing time across network. 0 Answers
Help with time.time when new scene starts. 1 Answer
It is not updated per second 0 Answers