Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by PixelFireXY · Nov 07, 2012 at 12:53 PM · timetime.deltatimetime.timedifference

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 =)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kryptos · Nov 07, 2012 at 03:30 PM 2
Share

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.

avatar image valyard · Nov 07, 2012 at 03:36 PM 0
Share

Damn, was pasting stuff in a hurry. Thanks, updated the post.

avatar image Kryptos · Nov 07, 2012 at 03:38 PM 0
Share

The name is really misleading. I think UT should rename it to Time.fixedDelay or move it to PlayerSettings.

avatar image AP54321 · Nov 30, 2019 at 02:27 PM 0
Share

@$$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."

avatar image Bunny83 AP54321 · Nov 30, 2019 at 03:25 PM 1
Share

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);


avatar image
8

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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 =]

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlucardJay · Nov 07, 2012 at 01:40 PM 0
Share

Wow, all these answers appeared, I was too slow =]

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get actual Time.deltaTime from FixedUpdate() 0 Answers

How do you add a time delay to this script ? 2 Answers

RigidBody MovePosition code acts differently by framerate 1 Answer

How to check if input was made x seconds/frames ago? 0 Answers

Want to load scene after taking off in plane. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges