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
0
Question by vsugrob · Dec 23, 2015 at 04:27 PM · startawakecrossplatformexecution order

Awake/Start order across different platforms.

I'm aware that I can't rely Awake () to be called in hierarchical or some other predictable order between builds and changes in a scene. However, I can observe that awakes will be invoked in the same exact order when neither code nor data were changed between runs. And this is a very important feature, especially when you write lock-step synchronization between clients. It makes you certain that every bit of synchronization-sensitive data gets initialized on all clients in the same exact way in every aspect. This leads to the following question: if I publish and deploy same exact code with the same exact data to some other platform, will this order remain intact? Is there any chance that developers of unity engine internals have some specification on this topic that they adhere to, upon writing runtimes for each platform?

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

Answer by Eric5h5 · Dec 24, 2015 at 01:35 AM

There is no guaranteed order for anything except as explicitly documented. So no, you can't expect GameObjects to run Awake functions in any particular order unless you do something to make that happen. Relying on undocumented behavior is pretty much 100% guaranteed to backfire...even if something works consistently now, it can and will change in the future.

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 vsugrob · Dec 24, 2015 at 02:02 AM 0
Share

Thank you. This knowledge saved a lot of my time and gave me certainty about which way I must go in further development.

avatar image
1

Answer by maccabbe · Dec 23, 2015 at 09:35 PM

http://docs.unity3d.com/Manual/ExecutionOrder.html

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 vsugrob · Dec 23, 2015 at 10:45 PM 0
Share

Probably there is a misleading information in my original post. $$anonymous$$y question was not about "what precedence of the Awake/Start/Update calls", but "do GO1, GO2 and etc. receive Awake () in the same order after deploying to a different platform? Same question about Start () and Update ()." Sorry for that. I guess, I have to add more details to my post.

avatar image
0

Answer by GiyomuGames · Dec 24, 2015 at 07:24 AM

A bit late but you can also specify the order of your scripts, which will force awake etc. to be called in a certain order: http://docs.unity3d.com/Manual/class-ScriptExecution.html

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 vsugrob · Dec 24, 2015 at 09:00 AM 0
Share

Thank you for your effort, but question was slightly different :) Consider scene with the following hierarchy:

 GameObject1
   Behaviour1
   Behaviour2
 GameObject2
   Behaviour1
   Behaviour2


Each behavior implements Awake () and writes into log string of the form "Awake():GameObject1:Behaviour1". After hitting play you can get following output:

 Awake() :GameObject1:Behaviour1
 Awake() :GameObject1:Behaviour2
 Awake() :GameObject2:Behaviour1
 Awake() :GameObject2:Behaviour2


Or you can get this:

     Awake() :GameObject1:Behaviour1
     Awake() :GameObject1:Behaviour2
     Awake() :GameObject2:Behaviour2
     Awake() :GameObject2:Behaviour1


In general, you can get almost any combination in output. However, it's only shuffled after you rebuild your project or change scene data. On the contrary: in subsequent runs with no modifications in code and data you get same output on each run. The question is: does order preserved in builds targeted to different platforms and can this behavior be relied upon?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Execution Order of Scripts - Awake and OnEnable 1 Answer

Cached references set in awake aren't persisting 0 Answers

Awake called after I activate object, not after Instantiate... is it normal?? 2 Answers

DontDestroyOnLoad() not calling awake/start again 2 Answers

Object reference becomes null between Awake and Start after scene load 2 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