- Home /
difference with Time.time, Time.deltatime, Time.frameCount
Someone can answer me about that please? I've already find in script reference but The total number of frames that have passed... I dont understand what meaning O.o Thanks in advance =)
Answer by valyard · Nov 07, 2012 at 01:37 PM
Most of the stuff in Unity runs in the main thread. Everything executes in order which is described here. A frame is one iteration of this cycle. A cycle where you got your Update method called, LateUpdate, after that everything is drawn on the screen — you got one whole FRAME drawn. With current framerate (number of frames drawn per second).
So, Time.time — time when current update cycle started. You can check this value in every method called during a frame cycle (like Update or LateUpdate) and it will be the same. When you press PAUSE this time stops increasing so the game time stops.
Time.deltaTime — basically it is how much time passed since the previous frame. You would usually use it in time dependant activities like moving things with constant speed: transform.position += Vector3.forward Time.deltaTime; If used in FixedUpdate it is time since last FixedUpdate* was called.
Time.fixedDeltaTime — delay between FixedUpdate calls where physics is calculated. Since physics tries to run with constant framerate.
Time.frameCount — the number of render cycles (rendered frames) since the start of the game.
UPDATE: Updated the post with Kryptos' feedback.
People always make the same mistake. I think Unity should rename it.
No Time.fixedDeltaTime is not the same as Time.deltaTime inside a FixedUpdate method.
Time.fixedDeltaTime is the expected fixed delta time value (the settings) but the actual delta time is still Time.deltaTime even inside a FixedUpdate.
Damn, was pasting stuff in a hurry. Thanks, updated the post.
The name is really misleading. I think UT should rename it to Time.fixedDelay or move it to PlayerSettings.
@$$anonymous$$ryptos the docs for Time.deltaTime are also really confusing by saying: "$$anonymous$$onoBehaviour.FixedUpdate uses fixedDeltaTime ins$$anonymous$$d of deltaTime." which some might be confused into thinking they're suggesting the opposite of what you've (correctly) said. Then in the Time.fixedDeltaTime docs they say explicitly what you've said: "For reading the delta time it is recommended to use Time.deltaTime ins$$anonymous$$d because it automatically returns the right delta time if you are inside a FixedUpdate function or Update function."
Though $$anonymous$$ryptos first statement is actually wrong / misleading because inside FixedUpdate Time.deltaTime and Time.fixedDeltaTime will return the same value and that is fixedDeltaTime. This is only true inside FixedUpdate. Time.fixedDeltaTime is not the "expected" deltaTime but the set deltatime for the fixedupdate loop that defines how many fixed update frames you will have per game time second. If you don't understand how this works, I recommend to have a look at my CustomFixedUpdate class I created which does the same thing that Unity does to implement FixedUpdate. I also created this animation several years ago (was originally a web player build) to visualize what happens.
The docs of fixedDeltaTime just suggests that you should simply always use deltaTime everywhere in case you might move code from Update to FixedUpdate or the other way round. It really doesn't matter if you use deltaTime or fixedDeltaTime inside FixedUpdate. However since Unity automatically returns the value of fixedDeltaTime when inside FixedUpdate there really is no reason to ever read fixedDeltaTime explicitly. The only exception I can think of are helper methods like those I wrote which depend on the fixedDeltaTime and might be called outside FixedUpdate since they can be used to precalculate the drag value required which you usually would do in Start.
I agree that the docs of deltaTime are a bit confusing. What they just wanted to express is that FixedUpdate does not "run every frame" but runs on a seperate timer. The sentence you quoted does not make any explicit statements on what value deltaTime / fixedDeltaTime return in which cases.
ps: $$anonymous$$y CustomFixedUpdate provides the "custom fixed delta time" value through a parameter to the callback. As you can see I always pass the set "m_FixedTimeStep" value as parameter when the callback is called:
m_Callback(m_FixedTimeStep);
Answer by Yokimato · Nov 07, 2012 at 01:37 PM
Each time the Update() function is called, it's been a frame. In other words, Update() is called once per frame.
Time.deltaTime is a float representing the difference (or the delta) in time (seconds) since the last update (or frame) occurred.
Time.frameCount will give you the total number of frames since you started the game. You could then of course think of this as how many times the Update method was called since the start.
Time.time is the total amount of time since the game started. (kind of like frame count but the units are in seconds rather than frames).
Answer by AlucardJay · Nov 07, 2012 at 01:39 PM
You missed one ... Time.fixedDeltaTime !
Everything you want and need to know is here : http://docs.unity3d.com/Documentation/ScriptReference/Time.html
for example, click on time : http://docs.unity3d.com/Documentation/ScriptReference/Time-time.html
The time this frame has started (Read Only). This is the time in seconds since the start of the game.
now go back and click deltaTime : http://docs.unity3d.com/Documentation/ScriptReference/Time-deltaTime.html
The time in seconds it took to complete the last frame (Read Only).
use the search box in the top-left to search all commands/functions/components =]