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
0
Question by joonhoriderlee · Dec 16, 2020 at 03:58 AM · physicstime.deltatimeupdate function

Should you use Time.deltaTime in FixedUpdate()?

I've seen many different answers online and all of them never giving a full reason on way you should or should not. The question is in thee title, Should you use Time.deltaTime in FixedUpdate().

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
2
Best Answer

Answer by lcplrice · Dec 16, 2020 at 04:05 AM

Time.deltaTime is the time between last frame. Inside FixedUpdate() this can sometimes cause odd behavior depending on the load running in any given frame and give unexpected results. Though I have never seen this. lol.

Unity recommends using Time.fixedDeltaTime in FixedUpdate() to help keep the behavior consistent.

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

https://docs.unity3d.com/ScriptReference/Time-deltaTime.html

Comment
Add comment · Show 4 · 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 joonhoriderlee · Dec 16, 2020 at 04:12 AM 0
Share

Thanks for answering so quickly this was really informative! :)

avatar image lcplrice · Dec 16, 2020 at 04:23 AM 0
Share

No problem, I was in the right place at the right time. :)

avatar image rhapen · Dec 16, 2020 at 08:28 AM 0
Share

just FYI. in most cases you will not needed in fixed update because fixedupdate is "fixed" therefore i += 1 / i++ would work just fine.

avatar image Edy · Dec 16, 2020 at 10:36 AM 1
Share

This answer is plainly wrong. Unity explicitly recommends using Time.deltaTime within FixedUpdate:

https://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html
> For reading the delta time it is recommended to use Time.deltaTime instead because it automatically returns the right delta time if you are inside a FixedUpdate function or Update function.

avatar image
3

Answer by Edy · Dec 16, 2020 at 10:35 AM

You should use Time.deltaTime everywhere, unless you need to consult the actual physics update rate. Time.deltaTime returns the proper value depending where are you reading it from.

From https://docs.unity3d.com/ScriptReference/Time-fixedDeltaTime.html :

> For reading the delta time it is recommended to use Time.deltaTime instead because it automatically returns the right delta time if you are inside a FixedUpdate function or Update function.

Comment
Add comment · Show 8 · 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 xxmariofer · Dec 16, 2020 at 11:31 AM 0
Share

There is no actual advantage over using Time.deltaTime over Time.fixedDeltaTime but to keep it simple for people who dont really understand the difference between Update and FixedUpdate, that unity recomendation is only for beginners

avatar image Edy xxmariofer · Dec 16, 2020 at 12:15 PM 0
Share

It's a general recommendation to all Unity users. Beginners should adhere to it so they don't use Time.fixedDeltaTime incorrectly. Just use deltaTime and everything will work as expected, anywhere.

The main advantage is that calculations that use the delta time will run correctly from either Update or FixedUpdate without changes.

Your answer states that using Time.deltaTime instead of Time.fixedDeltaTime from FixedUpdate can cause odd behavior depending on the load. That's simply incorrect. Can you justify it?

avatar image xxmariofer Edy · Dec 16, 2020 at 12:26 PM 0
Share

Justify what? The accepted answer from the other guy? he is incorrect saying that it can cause odd behaviour. I just pointed out that deltaTime and fixedDeltaTime inside the FixedUpdate will always return the same value

Show more comments
avatar image shieldgenerator7 · Dec 18, 2020 at 10:31 PM 0
Share

its only been 2 days and Unity already says your link is broken :/

avatar image xxmariofer shieldgenerator7 · Dec 19, 2020 at 10:21 AM 0
Share

Remove the last : from the link

avatar image Edy xxmariofer · Dec 19, 2020 at 12:32 PM 0
Share

Fixed. Stupid auto-link feature using the trailing colon as part of the url...

avatar image Pioo · May 28, 2021 at 05:19 PM 0
Share

this answer should labeled "Best answer", it says everything

avatar image
0

Answer by shieldgenerator7 · Dec 18, 2020 at 10:29 PM

After reading @Edy 's answer, I had to do some tests. Here's the results:

alt text

(AvC is a poor man's outlier elimination: it removes the smallest and largest values, then averages the remaining values)

As you can see, deltaTime fluxuates in Update() but always returns 0.02 in FixedUpdate(). Whereas fixedDeltaTime always returns 0.02 no matter where it's called. This leads me to believe that fixedDeltaTime is a setting rather than a reading of how long the last frame took.

Based on these results, it looks like you can use either one in FixedUpdate(), although Unity does recommend using deltaTime there too.

But most definitely, you should use deltaTime in Update()


unity-test-deltatime.png (39.5 kB)
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 xxmariofer · Dec 19, 2020 at 10:22 AM 0
Share

Yes fixeddeltatime is a value that you can modify from the project settings window

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

233 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 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 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 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 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 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 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 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 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

Changing Time.fixedDeltaTime to create slowmotion messes up with physics. 1 Answer

Not registering input when checking input in Update and using input in FixedUpdate 1 Answer

Does AddForce use Time.deltaTime or TIme.fixedDeltaTime or it depends on whether it is being used in Update() or fixedUpdate()? 2 Answers

Raycast and Physics(Ragdolls): Update() or FixedUpdate()? 1 Answer

Aim helper in realistic sniper game 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