what is the difference or relationship between these 2.
Have you tried reading the documentation for the two properties? Do you have a more specific question about them?
Time.fixedDeltaTime is a read/write property to set what the physics update rate is. The simulated delta time between FixedUpdate calls.
Time.deltaTime is the change in time between update calls. If accessed during the Update call, itās the time since last Update call. If accessed during FixedUpdate, itās the fixedDeltaTime.
Please read the documentationā¦
Also important to note:
FixedUpdate happens at the same rate every single frame. That is why it is generally used for physics. Update does not.
This is important to note because Time.fixedDeltaTime uses whatever that physics update rate is. As lordofduct said above, itās just a read/write property.
Regular Time.deltaTime uses the time between update calls, which isnāt necessarily the same every frame at all since different things affect it.
I did read the documention like always but its always confusing.
Which part was confusing?
umā¦ he said Time.time, not deltaTimeā¦ not sure if this was a mistake. anyhoo
Time.deltaTime = Time delta (difference) between frames
Time.fixedDeltaTime = Physics time step
Time.time = Total time since game started (game timer if you will)
Oh wow, good call. I was going based off what lordofduct wrote instead of the actual title of the post.
Nobody actually answered the question yet! To be fair, I can see why you all are assuming that the OP is asking about fixedDeltaTime, since I havenāt actually ever seen anybody use fixedTime (had to double-check that it actually exists), but still.
Now, Time.time and Time.fixedTime are pretty well documented, but you have to understand how Update and FixedUpdate frames work to understand the docs.
The short version is this:
Time.time is the last point at which the engine started running Update on all your scripts.
Time.fixedTime is the last point at which the engine started running FixedUpdate on all your scripts.
As a further complication, if you are inside a FixedUpdate function, Time.time returns Time.fixedTime instead. This is consistent with Time.deltaTime, which gives you Time.fixedDeltaTime inside FixedUpdate.
The long version (still somewhat simplified, and based of heuristics and hearsay):
The underlying physics calculation of Unity is a simulation. It doesnāt have its internal āclockā, instead, Unity asks it to simulate that a certain amount of time has passed - letās call this simulation step a physics ātickā. The amount of time simulated in each of these ticks is a value called the fixed timestep, which is a value you can set for your game.
The FixedUpdate function is run in sync with these ticks - so per tick, you get one FixedUpdate. I believe that FixedUpdate happens directly after the tick (as opposed to directly before), but Iām not completely sure about that.
The Update function, on the other hand, runs as often as Unity manages to call it, and is synced to Unity drawing everything on your screen. The rate of your Update function is roughly equivalent to what you generally call Frames Per Second - fps (not related to First Person Shooter in any way).
After Unity calls Update, it checks how long it is since it called FixedUpdate last. If that time is larger than the fixed timestep - the wanted tick interval - it calls FixedUpdate. In fact, it runs FixedUpdate enough times to catch up to where the physics simulation āshouldā be. So if the last time FixedUpdate was run was at 2.00 seconds, the fixed Timestep is at 0.02 seconds, and Update finished at 2.11 seconds, FixedUpdate will be called 5 times, until the physics engine has simulated up to 2.10 seconds.
Note that all Update and all FixedUpdate functions on all your MonoBehaviours are called in one go. The value of Time.time in any of those Update function is the ārealā time at which Unity started calling the first of them. Similarly, Time.deltaTime is the ārealā time between this round of Updates, and the last round of Updates.
The value of Time.fixedTime within each of those FixedUpdate functions, though, is the time the physics engine were simulating when those FixedUpdate functions were called. Similarly, the value of Time.fixedDeltaTime is the duration of the simulated tick - ie. 0.02 seconds if your fixed timestep is 0.02. In essence, Time.fixedDeltaTime never changes.
Final note: Iām writing ārealā time under Update since itās not actually real time - if you change the value of Time.timeScale, Time.time respects that. So if your timeScale is 2, Time.time increses twice as fast, while with timeScale at 0.5, Time.time increases half as fast.
If you need the actual real time since the game started, use Time.realTimeSinceStartup, which uses your systemās internal clock.
Hope thatās informative!
Heh, just noticed he did say time and fixedTime. Dyslexia must have been in high gear yesterday.
I still do not get it but i should stop coming to this forums for i have figured out its not for me and 9/10 times i donāt find my answers here but from some external source whatever that may beā¦(google? nah donāt think so more like you tube well google does own youtube so i guess you can say google)
lol. poor @Baste
You sound like you might be a visual learner. Rather than learning from text.
yeahā¦your time was not wasted @Baste
Isnāt text something to see? (just kidding)
I was being serious. Some people are just better at learning visually.
I know I was making a joke and saying text is something you see.
lol i love that joke, i will steal that.
Actually, this question comes up so many times that I figured itād be nice to have a proper write-up I can refer back to.
real slickā¦