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
5
Question by xxufl · Jan 07, 2015 at 07:03 PM · updateaddforcefixedupdatetime.deltatime

Should we use Time.deltaTime in FixedUpdate

I know this question has been asked once http://answers.unity3d.com/questions/530478/is-it-even-necessary-to-multiply-by-timedeltatime.html but it looks as though it has not been settled. The first few answers only talk about how AddForce shouldn't have Time.deltaTime because it has it inherently. The last answer(as of now) by FrimaMickD says not to use Time.deltaTime inside FixedUpdate and it makes sense to me because no matter what computer, FixedUpdate will be called at the same rate all the time(as far as I know, quote me if I'm wrong) and Time.deltaTime is there to remedy problems that could occur inside the Update function because framerates may vary over time, and on different computers. However, I've seen official Unity tutorials using Time.deltaTime inside FixedUpdate and also in the comment section of FrimaMickD's answer it looks as though sb is suggesting that Time.deltaTime needs to be used inside FixedUpdate in certain cases. Can someone please resolve this issue it's been driving me crazy.

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Jan 07, 2015 at 07:08 PM 1
Share

If you edit your post, and tell us what Unity tutorials use deltaTime inside FixedUpdate, I'll go find whoever wrote the code and get them to explain. I suspect it's just dodgy code.

avatar image xxufl · Jan 08, 2015 at 01:21 AM 0
Share

I'll just right them here. 11:16 in http://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player and the movement variable in http://unity3d.com/learn/tutorials/projects/survival-shooter/player-character

6 Replies

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

Answer by Kiwasi · Jan 08, 2015 at 01:50 AM

If you move a transform by modifying its position directly then use Time.deltaTime. If you want any time based effects use Time.deltaTime.

Don't use Time.deltaTime with forces, forces are not a time based effect.

This advice is true if you are using Update or FixedUpdate.

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 xxufl · Jan 08, 2015 at 02:02 AM 0
Share

But I thought FixedUpdate had constant framerate on its own. Am I just wrong about that fact? because in which case just using FixedUpdate would take care of problems that my occur in time based effects

avatar image Kiwasi · Jan 08, 2015 at 02:07 AM 2
Share

FixedUpdate has a constant frame rate, unless you modify it. You can modify it for several reasons

  • During development, to squeeze extra performance or accuracy out of the physics engine

  • At run time to match time scale changes

So putting Time.deltaTime into FixedUpdate insulates your code against any changes to the 'constant' frame rate.

Its also worth noting as indicated by @Graham Dunnett that normal practice is not to have any time dependent stuff in FixedUpdate. But if you do put it there, use Time.deltaTime.

avatar image xxufl · Jan 08, 2015 at 02:09 AM 0
Share

Thank you! That really cleared up my frustration

avatar image InvincibleCat · Jan 08, 2015 at 02:11 AM 0
Share

Agree. For performance reason you may change fixedDeltaTime in settings, so all your values will be wrong if you don't use Time.deltaTime!

avatar image xxufl · Jan 08, 2015 at 02:15 AM 0
Share

does multiplying by Time.deltaTime affect the size of the variable? Like Owen Reynolds's answer from http://answers.unity3d.com/questions/530478/is-it-even-necessary-to-multiply-by-timedeltatime.html ? And I get that we should use them when directly modifying an object's position, but should we use Time.deltaTime when using Forces and modifying Euler rotation too?

Show more comments
avatar image
13

Answer by InvincibleCat · Jan 07, 2015 at 07:23 PM

Here is the answer: "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."

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

So yes, use Time.deltaTime ;)

Cheers

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 tanoshimi · Jan 07, 2015 at 08:09 PM 0
Share

Whether you use deltaTime or fixedDeltaTime rather depends on what for... they're two different things.

avatar image xxufl · Jan 08, 2015 at 01:29 AM 0
Share

Well, all other purposes aside, I was just wondering if we should use Time.deltaTime inside FixedUpdate with intent to resolve the problem which occurs due to having different framerates in different computers. Like as we would multiply the Time.deltaTime function inside a variable inside the Update function in certain cases. I appreciate your answer but I since I don't seem to completely grasp your point I'd be grateful if you could elaborate on your point a bit more thankx s :)

avatar image InvincibleCat · Jan 08, 2015 at 01:31 AM 0
Share

fixedDeltaTime shouldn't be use to resolve the problem which occurs due to having different framerates in different computers. Always use Time.deltaTime :)

avatar image xxufl · Jan 08, 2015 at 01:42 AM 0
Share

But do we have to worry about that kind of problem inside FixedUpdate? I thought since FixedUpdate will have its own fixed framerates we wouldn't really have to worry about it and use Time.deltaTime

avatar image InvincibleCat · Jan 08, 2015 at 01:47 AM 0
Share

Oh I see, no, you need it! It still uncertain so use it, it's a best practice

Show more comments
avatar image
3

Answer by Graham-Dunnett · Jan 07, 2015 at 07:07 PM

Well, use Time.deltaTime inside your FixedUpdate() if you want to include how many seconds the previous frame took to render. There is a Time.fixedDeltaTime which tells you the time between fixed updates. Since I've never seen any fixed update code that needs to know how long the previous frame took, I'd say don't use Time.deltaTime inside a FixedUpdate().

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 xxufl · Jan 08, 2015 at 01:23 AM 0
Share

So we don't need Time.deltaTime inside FixedUpdate if the purpose is to adjust the intervals like we would inside Update right? thanks

avatar image
2

Answer by UpitSoft · Mar 31, 2021 at 05:51 AM

Time.deltaTime returns Time.fixedDeltaTime in FixedUpdate(). You can try it ;)

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
0

Answer by JustHallowed · Mar 18, 2021 at 03:07 AM

Offtopic but I think Time.fixedDeltaTime could be used for coroutines if it is used for some sort of physics calculation.

 IEnumerator MoveTowardsWaypoint()
 {
             while(doLoop)
             {
                 transform.position = transform.position + direction * Time.fixedDeltaTime;
                 yield return new WaitForFixedUpdate();
             }
 }
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
  • 1
  • 2
  • ›

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

13 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

Related Questions

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

AddForce in Update 1 Answer

FixedUpdate vs. Update for instantaneous ForceMode's 1 Answer

Slow update best practice 0 Answers

Interpolation with jumping - Acting Weird. 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