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 jtsmith1287 · Aug 30, 2014 at 10:05 PM · updatetimefixedupdateinvokerepeating

InvokeRepeating OR Update OR FIxedUpdate?

I'm basically thinking to avoid modifying every calculation with Time.deltaTime, could I just do an InvokeRepeating and haveit run at 30 or 60 fps (or whatever works) instead of putting time sensitive stuff in Update? ALternatively, while UT recommends using FixedUpdate for physics, could/should I use FixedUpdate to handle every other time sensitive calculation as well?

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 Kiwasi · Aug 30, 2014 at 10:37 PM 1
Share

Just to confuse the issue more you could also use coroutines.

avatar image jtsmith1287 · Aug 31, 2014 at 02:32 AM 0
Share

In response to OboShape, B$$anonymous$$ayne, and Bored$$anonymous$$ormon: I suppose I should clarify that while execution efficiency is important, I'm mostly looking for coding efficiency in this case. It would be very easy to forget to add a time.deltaTime call in a calculation and neeeeeever know until the user reports some strange occurances. I know this is all on the programmer's shoulders, so to speak, but if I could do away with the call altogether for fixed interval calculations that sure would be nice. I'm interested in InvokeRepeating via coroutine, now that you mention it, haha.

2 Replies

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

Answer by BMayne · Aug 31, 2014 at 12:31 AM

Hey JTSmith,

Don't be afraid of your friend Time.deltatime. Computer are super fast and doing that very simple math will not in that slightest have an effect your framerate. Using Invoke repeating would have more overhead then using your own timer system.

One thing that sucks about InvokeRepeating is that you have no control when it is really called (ie. [After/before/during] Update, [After/before/during] animations, [After/before/during] FixedUpdate). This does not sound like an issue but you have you other classes that depending on the function being called before they update on the same frame you might be out of luck.

What I suggest is making a simple timer class that you can use over and over again to call your functions. If you know how to use Delegates this is super easy to do.

Let me know if you have any other questions.

Regards,

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 BMayne · Aug 31, 2014 at 12:32 AM 0
Share

Also use Update with Time.delta time and not FixedUpdate for non-physics stuff.

avatar image jtsmith1287 · Aug 31, 2014 at 02:34 AM 0
Share

Why are you against FixedUpdate?

avatar image BMayne · Aug 31, 2014 at 02:42 AM 1
Share

Fixed update can run faster or slower then update (this depends on your framerate). Say you had the class below

 int fixedValue = 0;
 int Value = 0;
 
 void Update()
 {
   Value++;
 }
 
 void FixedUpdate()
 {
   fixedValue++;
 }
   

Now if your game was running at 60 frames after a while both Value and FixedValue will be the same.

If your game was running slow FixedValue would be greater then Value (how much is based on how slow)

If your game was running faster then 60 FixedValue would be less the Value.

(For my quick math I just guess that 60 frames is what fixed update is set to do)

This can lead to broken logic in your game that will be very hard to find.

avatar image jtsmith1287 · Aug 31, 2014 at 02:55 AM 1
Share

Fair enough. Sounds like sound logic to me. :)

avatar image
0

Answer by OboShape · Aug 31, 2014 at 12:11 AM

Hope im getting the gist of this JTSmith,

time.deltatime can be used in update or fixed update. deltaTime is the time difference between calls be it fixedupdate or update.

as far as I understand InvokeRepeating() uses a time difference in seconds, so therefore using deltatime behind the scenes based on your current target platform framerate to give you a call every x seconds.

certainly use fixedupdate for any physics movement etc, as update will not run in sequence with fixedupdate and you could get some shonky movement etc.

have a little look at the tutorial in the learn section, for a bit more info http://unity3d.com/learn/tutorials/modules/beginner/scripting/delta-time

im by no means any kind of expert but this is just what i interpret it to mean, if i understand it wrong then someone please correct me please :)

dont want to lead you up the preverbial garden path.

DaZ

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

25 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

Related Questions

Fixed timestep... 1 Answer

Slow update best practice 0 Answers

How often does the internal physics calculation get called? 1 Answer

Interpolation with jumping - Acting Weird. 1 Answer

Is there an equivalent of Time.frameCount for physics updates? 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