# Time.smoothDeltaTime ???

(This was asked in the WishList Topic, but I feel my reply would be more helpful, and more properly put, here.)

``````  smoothDeltaTime = (current delta time + (sum of 'n' previous delta times)) / ('n' + 1)
``````

Using smoothDeltaTime limits the effect of sudden fluctuations in deltaTime.

Example:

``````    deltaTime          smoothDeltaTime ('n' = 2)
--------           -------------------------
...		          ...
0.25               0.25
0.25               0.25
0.25               0.25
0.95 (+380%)       0.4833 (+193%)
0.25 (-73%)        0.4833
0.25               0.4833
0.25               0.25   (-51%)
0.25               0.25
...                ...
``````

In the table above, you see deltaTime is going along steadly at 0.25, but then suddenly it spikes up 380% to 0.95 then drop down 73% to 0.25. The visual effect of the spike would be everything suddenly moving 380% more units than the previous frame.

The smoothDeltaTime, since the values are averaged over several frames, only sees a jump of 193%. And when it does drop back down to normal, the drop is only 51%. Now, while there will still probably be a visually noticible â€śhitchâ€ť, it wonâ€™t be as drastic as the deltaTime hitch. The hitch will have been spread, or â€śsmoothedâ€ť, out over several frames.

I agree, it would be nice if some of the descriptions where expanded on, but hopefully my little description will help in the mean time (and is not too far off the actual mark)

11 Likes

Thank you for sharing.
The documentation hasnâ€™t been updated yet :-/

I didnâ€™t even know there was such a thing as smoothDeltaTime. Thanks for explaining this. Iâ€™m sure I will use this at some point.

Just for information if any docs manager comes by this section :
April 2012 (4 years later), and the docs about it are still vague. I had to Google search â€śsmoothDeltaTimeâ€ť to find out further explanations here.

2 Likes

The doc is quite hurting in some parts. I wonder why they didnâ€™t make a wiki version where anyone could contribute to keep things updated.

6 Likes

Cause the docs also have to be accessible offline and it doesnâ€™t work with Wikis?

You can have manual for offline use + an online version and a separate wiki just for online where users can add things. Many applications use this sort of method and it works wonderfully.

2 Likes

Thanks DGuy for the useful information, and thanks n0mad for bumping this

Unity docs should really be taken more seriously by the Unity guys. The amount of time that a Unity user has to lose to get information about things that should be well documented is absurd. Online searches, forum help, direct trial and error testing. And all this not to find solutions to issues, but just to understand undocumented (or badly documented) API. If we count these hours as working hours, Unity costs a LOT more than 1,500\$.

3 Likes

Should it not be possible to have a community driven wiki then?
Someone just have to set one up and Iâ€™m sure many will contribute to it.

2 Likes

why canâ€™t they just add a comments section to the docs like they have on php.net?! everyone could add clarifications and examples and everyone on the planet would benefit greatly!

3 Likes

This. All day, this.

Not that the resources arenâ€™t great as they are, but having something a bit more expanded than this kinda (understandably) rushed doc note would be great.

1 Like

Ahh, thanks for the explanation. The current docâ€™s explanationâ€”â€śSmooths the delta timeâ€ťâ€”could mean a hundred different things.

2 Likes

From my experimentation Unity calculates it as a linear combination of current frame time and previous smoothed time like this:

newSmoothDeltaTime = f*Time.deltaTime+(1-f)*prevSmoothDeltaTime

Where they seem to use f=0.2 (In Unity 5 at least)

In the end I had to implement it myself because Time.smoothDeltaTime seems to be updated also when the timeScale is zero causing it to be nearly zero after my game was unpaused.

7 Likes

Wow. 7 years(!) later the docs page for this hasnâ€™t changed.

2 Likes

The documentation almost never has the exact math that goes into any of its built-in methods and members, so this is just one of a million different things that have some magic going on behind the scenes, and no reason (or at least, no more than normal) to update the documentation. Anyways, theyâ€™ve been more focused on those promotional videos that they call tutorials.

2 Likes

Smooth delta time does exactly what it says.If there is a significant jump in the framerate youâ€™re running, SmoothDelta time will report values closer to your targetFPS but weighted by the amount of frame loss. deltaTime will give you the actualy time difference.

Or might the reason about silly of their document for a big community then you all are here