Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ehaase · Jul 20, 2011 at 10:04 PM · updatesynchronizationthreads

Are Update() and FixedUpdate() called in different threads?

http://unity3d.com/support/documentation/Manual/Update%20Order.html

suggests that FixedUpdate() and Update() are called independently, i.e. if the Update() Callback gets stuck for a second, it does not say FixedUpdate() would wait at all. Thus, if I call the same method from Update() and from FixedUpdate(), would I need to synchronize (mutually exclude threads calling a critical code section)?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by Eric5h5 · Jul 20, 2011 at 10:36 PM

No, Unity scripts are all run in the same thread. If Update gets stuck for a second, the entire game will freeze for a second.

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 Bunny83 · Jul 20, 2011 at 10:43 PM

No, the whole scripting runs in one thread. The whole scripting API therefore isn't thread-safe. You can use your own thread but you can't access the API (unity checks the threadID).

FixedUpdate is not run in "fix" intervals. It's a "fixed" Update. It just runs before Update (at least i guess, maybe right after update). It's deltaTime value has a fix value but it doesn't match the realtime. If you have only 30 fps and have a fixed rate of 60, FixedUpdate will be called twice before the next update. If you have 120 fps FixedUpdate is only called every second frame. The acumulated calls will reflect a 60fps rate but it's just "corrected" ;)

http://www.unifycommunity.com/wiki/index.php?title=Event_Execution_Order

Comment
Add comment · Show 2 · 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 ehaase · Jul 21, 2011 at 08:50 AM 0
Share

Only one thread, okay.

But... "deltaTime has a fix value but it doesn't match the realtime" - can you please elaborate on that?

I mean, if I trap Update() for a second then return, and I have FixedUpdate at 60Hz, does that mean I have 60 "FixedUpdate" calls before "Update" is called again?

And do I have to use less computing time than 1sec/60 for every call into FixedUpdate? What happens if I slip and I need 1.2sec/60 for a few calls into FixedUpdate during that said second?

avatar image Eric5h5 · Jul 21, 2011 at 09:06 AM 0
Share

@ehaase: Theoretically, yes you could have 60 FixedUpdate calls in a row, but realistically the maximum allowed timestep value in the time settings prevents that. (The side effect is that physics are slowed down if it kicks in.) If you are using so much CPU time in FixedUpdate that you're preventing it from running at the specified interval, basically your code is broken and you need to fix that by massively reducing the amount of code in FixedUpdate or substantially reducing the number of times FixedUpdate runs per second. But if it was just a brief hiccup, FixedUpdate will always attempt to run at the specified interval by running more frames after that, again with the maximum allowed timestep functioning as a sort of "brake" if necessary.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

FixedUpdate performance doubts 2 Answers

Music composing in Unity? 0 Answers

Load Previously Instantiated Network Objects 1 Answer

Does ManualResetEvent work in the Unity runtime? 0 Answers

while Looping 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