Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by PushkarSawant97 · May 23, 2014 at 08:23 AM · androidupdatelagfixedupdatedeltatime

Exact difference between fixedDeltaTime and deltaTime?

Hello.

P.S. :Whatever I say is regarding mobile platform but may apply to other platforms as well.

I have read that to make a game frame rate independent, one must multiply all calculations with Time.deltaTime which is basically the time required to complete the last frame. However, when the system slows down or when relatively heavy background applications pop-up,(which I have experienced first hand) the game also starts lagging. However when I multiply the same calculations with Time.fixedDeltaTime, the game runs exactly at a specific rate or "speed" no matter how many background applications pop-up mid game play. So this would be the best way to do it right? Well actually, NO! When I run the same game on another system(phone), the speed or rate of the game is altered. Case in point, when I play the game on my SGS4 it runs faster than on another slightly lower end device.

THE QUESTION: THE LAG THAT I EXPERIENCE WITH Time.deltaTime, is that lag natural? Is it acceptable? I mean, a lot of games made by professional developers DO LAG!

Also,any reason why my game runs so jerky on the other device but runs so smooth on my SGS4? It's a relatively simple game, not very heavy.Neither GPU intensive,nor RAM intensive.

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
15

Answer by MrVerdoux · May 23, 2014 at 08:58 AM

I don't know the reason your game lags but the use you are giving to Time.deltaTime and Time.fixedDeltaTime is possibly wrong.

Time.deltaTime is the time interval between current frame and the last one, which is the same than the time interval between two call to the Update() method. This means that Update() is going to be called a different number of times depending on the performance of your game.

On the other hand you have the method FixedUpdate() which works essentially as Update() but with the difference that it is going to be called a fixed amount of times per second. Naturally Time.fixedDeltaTime is the difference between two calls of FixedUpdate() and it always holds the same value.

As you see, it would make no sense using Time.fixedDeltaTime in the Update() method, if you do so you should move the logic that uses Time.fixedDeltaTime to the FixedUpdate() method. Same goes for Time.deltaTime, it is wrong (or at least very wierd) to use it in FixedUpdate().

Personally I use Update() for input recognition, since it is more likely to catch a key because it gets called more often. I use FixedUpdate() for everything else.

Comment
Add comment · Show 6 · 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 PushkarSawant97 · May 24, 2014 at 05:25 PM 0
Share

Could the reason possibly be because the game object that I'm talking about doesn't have a rigidbody or rigidbody2D? It moves with the help of code like :

"transform.position.x += someValue Time.deltaTime" OR "transform.position.x += someValue Time.fixedDeltaTime"

avatar image Ferb · Nov 01, 2014 at 05:52 PM 0
Share

You would be recommended to multiply someValue by Time.deltaTime. Time.fixedDeltaTime would be suitable if you are in a FixedUpdate function (as opposed to just an Update), but even then Time.deltaTime will work fine, because that automatically returns the right value depending on whether you are in an Update or a FixedUpdate function. Of course, there's a limited amount they can do to prevent lag - if your virus scanner starts up and slows your game down to a few frames a second, it will be noticeable regardless of having used Time.deltaTime.

avatar image Xonatron · Jan 18, 2018 at 12:04 AM 0
Share

$$anonymous$$odifying Time.timeScale appears to modify Time.deltaTime and Time.fixedDeltaTime both away from the amount of time between the last two frames. If you set Time.timeScale = 0.5f, it will halve the values in both delta times. Can you explain what is happening?

What I was expected was there to be a value that gives the actual delta time in reality and another to give the delta time in the game (which would be halved), if you understand how I am thinking about this.

Please explain if you will.

avatar image Bunny83 Xonatron · Jan 18, 2018 at 01:50 AM 1
Share

Yes, the point of the timescale is to affect the perceived time. So at a timeScale of 0.5 everything should move half as slow as usual. This is done by scaling deltaTime by the timeScale. If every delta calculation uses Time.deltaTime, everything will advance slower when the timescale is lowered.


If you check the documentation you will notice that there is also an unscaledDeltaTime. However you almost never need this. Where it might come in handy is when you want to have some specific things to still run when you set the timescale to 0 to pause the game.


If you have any further questions, please ask a seperate question. Comments are not meant to ask questions or to answer them.

avatar image Xonatron Bunny83 · Jan 18, 2018 at 03:47 AM 0
Share

unscaledDeltaTime is good for fps calculations though. Thanks a lot for the breakdown. Note my "Answer" below too, as I learned a bit more about all of this in the meantime.

Show more comments
avatar image
2

Answer by J-Rich · Jul 27, 2019 at 08:36 PM

You should use Time.deltaTime whether you're in FixedUpdate or Update. It will return the actual amount of time that has elapsed between calls of the method you use it in (it automatically detects whether its in FixedUpdate or Update and returns the correct value).


Time.fixedDeltaTime is the target update rate for FixedUpdates. The actual time elapsed between FixedUpdate calls may not match it.

See https://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html (The docs recommend you use Time.deltaTime instead)

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 Xonatron · Jan 18, 2018 at 12:14 AM

Time.fixedDeltaTime is a value to set, not read:

  • Time.deltaTime is the amount of time between frames -- the inverse of which would be your frames per second. It is a value you READ. It cannot be set.

  • Time.fixedDeltaTime relates to physics, and is the same interval. However, it is a value you SET. You can also read it. One use is to modify it when you do slow down, so your physics works: "Note that the fixedDeltaTime interval is with respect to the in-game time affected by timeScale."

Source: https://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.htmlhttps://docs.unity3d.com/ScriptReference/Time-timeScale.html

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

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

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Movement lag, jitery every few seconds 1 Answer

Android update issue 0 Answers

Problem with animation and void fixedupdate() 1 Answer

Lerp stopping/not working? 1 Answer

Bad Performance on Mobile. 0 Answers


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