For a given frame rate in frames per secondThe frequency at which consecutive frames are displayed in a running game. More info
See in Glossary (FPS), the duration of individual frames tends to vary. These variations can be minor. For example, in a game running at 60 FPSSee first person shooter, frames per second.
See in Glossary, the actual number of frames per second may vary slightly, so that each frame lasts between 0.016 and 0.018 seconds. Larger variations can occur when your application performs heavy computations or garbage collection, or when there’s competition for resources from other applications.
Time.time indicates the amount of time elapsed since the start of the application, and so usually rises continuously and steadily. Time.deltaTime indicates the amount of time elapsed since the last frame, and so ideally remains fairly constant. Both these values are based on in-game rather than real time, which means they take into account any scaling of time that you apply. For example, if you set Time.timeScale to 0.1 for a slow-motion effect, the value of Time.time
increases at 10% the rate of real time. After 10 seconds of real time, the value of Time.time
would have increased by 1.
In addition to slowing down or speeding up time in your game, you can set Time.timeScale
to zero to pause your game. In this case Unity still calls the Update
method, but Time.time
does not increase at all, and Time.deltaTime
is zero.
These values are also capped by the value of Time.maximumDeltaTime. The length of any pauses or variations in frame rate reported by these properties will never exceed Time.maximumDeltaTime
. For example, if a delay of one second occurs, but maximumDeltaTime
is set to the default value of 0.333, Time.time
wonly increases by 0.333 and Time.deltaTime
equals 0.333, despite one second elapsing in the real world.
The unscaled versions of each of these properties (Time.unscaledTime and Time.unscaledDeltaTime) ignore these limitations, and report the actual time elapsed in both cases. This is useful for anything that should respond at a fixed speed even when the game is playing in slow-motion. An example of this is UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary interaction animation.
The table below shows an example of 16 frames elapsing one after another, with one large delay occuring half-way through, on a single frame. These figures illustrate how the various Time
class properties report and respond to this large variation in frame rate.
Frame | unscaledTime | time | unscaledDeltaTime | deltaTime | smoothDeltaTime |
---|---|---|---|---|---|
1 | 0.000 | 0.000 | 0.018 | 0.018 | 0.018 |
2 | 0.018 | 0.018 | 0.018 | 0.018 | 0.018 |
3 | 0.036 | 0.036 | 0.018 | 0.018 | 0.018 |
4 | 0.054 | 0.054 | 0.018 | 0.018 | 0.018 |
5 | 0.071 | 0.071 | 0.017 | 0.017 | 0.018 |
6 | 0.089 | 0.089 | 0.018 | 0.018 | 0.018 |
7 | 0.107 | 0.107 | 0.018 | 0.018 | 0.018 |
8 (a) | 1.123 (b) | 0.440 (c) | 1.016 (d) | 0.333 (e) | 0.081 (f) |
9 | 1.140 | 0.457 | 0.017 | 0.017 | 0.066 |
10 | 1.157 | 0.474 | 0.017 | 0.017 | 0.056 |
11 | 1.175 | 0.492 | 0.018 | 0.018 | 0.049 |
12 | 1.193 | 0.510 | 0.018 | 0.018 | 0.042 |
13 | 1.211 | 0.528 | 0.018 | 0.018 | 0.038 |
14 | 1.229 | 0.546 | 0.018 | 0.018 | 0.034 |
15 | 1.247 | 0.564 | 0.018 | 0.018 | 0.031 |
16 | 1.265 | 0.582 | 0.018 | 0.018 | 0.028 |
Frames 1 to 7 are running at a steady rate of approximately 60 frames per second. You can see both Time.time
and Time.unscaledTime
increasing steadily together, indicating that Time.timeScale
is set to 1.
On frame 8 (a), a large delay of just over one second occurs. This can happen when there is resource competition. For example, an operation blocks the main process while it loads a large amount of data from disk.
When a frame delay exceeds Time.maximumDeltaTime
, Unity limits the value reported by Time.deltaTime
and the amount added to Time.time
. This avoids undesirable side-effects that might occur if the time step exceeds that amount. Without the limit, objects whose movement is scaled by Time.deltaTime
can theoretically move unlimited distances from one frame to the next. This can cause a glitching effect where, for example, characters pass through obstacles such as walls unimpeded.
You can adjust Time.maximumDeltaTime
in the Editor by changing the Maximum allowed timestep setting in the Time window or in code by setting the value of the Time.maximumDeltaTime property.
The default Time.maximumDeltaTime
value is one third of a second (0.3333333). This means that in a game where movement is controlled by Time.deltaTime
, an object’s movement from one frame to the next is limited to the distance it could cover in a third of a second, regardless of how much time actually elapsed since the previous frame.
Looking at the data from the table above in graph form can help to visualise how these time properties behave in relation to each other:
On frame 8, Time.unscaledDeltaTime
(d) and Time.deltaTime
(e) differ in how much time they report has elapsed. Although a whole second of real time elapsed between frames 7 and 8, Time.deltaTime
reports only 0.333 seconds. This is because Time.deltaTime
is capped to the Time.maximumDeltaTime
value.
Similarly, Time.unscaledTime
(b) has increased by approximately a whole second because the true (uncapped) value has been added, whereas Time.time
(c) has only increased by the smaller capped value. Time.time
does not catch up to the elapsed real time, and instead behaves as though the delay was only Time.maximumDeltaTime
in duration.
The Time.smoothDeltaTime
property reports an approximation of the recent Time.deltaTime
values with all variations smoothed out according to an algorithm. This is another technique to avoid undesirable fluctuations in movement or other time-based calculations. In particular, those which fall below the threshold set by Time.maximumDeltaTime
. The smoothing algorithm can’t predict future variations, but it gradually adapts its reported value to smooth out variations in the recently elapsed Time.deltaTime
values, so that the average reported time remains approximately equivalent to the actual amount of time elapsed.
The maximumDeltaTime
value also affects the fixed update loop. The physics system uses the fixed time interval defined by Time.fixedDeltaTime
to determine how much time to simulate in each step. Unity tries to keep the physics simulation up-to-date with the amount of time that has elapsed and sometimes performs multiple physics updates per frame.
However, if the physics simulation falls too far behind, the physics system may require a large number of steps to catch up to the current time. These catch-up steps may themselves cause additional slow-down. To avoid a feedback loop of slow-downs, the Time.maximumDeltaTime
value also acts as a limit on the amount of time the physics system simulates between any two given frames.
If a frame update takes longer than Time.maximumDeltaTime
to process, the physics engineA system that simulates aspects of physical systems so that objects can accelerate correctly and be affected by collisions, gravity and other forces. More info
See in Glossary does not try to simulate any of the additional time, and instead lets the frame processing catch up. Once the frame update has finished, the physics resumes as though no time has passed since it stopped.
The result of this is that physics objects won’t move perfectly in real time as they usually do, but will be slowed slightly. However, the physics system still tracks them as though they were moving normally. The slowing of physics time is usually not noticeable and is often an acceptable trade-off against gameplay performance.
The following flowchart illustrates the logic that Unity uses to count time in a single frame, and how the time, deltaTime, fixedDeltaTime, and maximumDeltaTime properties relate to each other.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.