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 Nananaaa · Oct 11, 2016 at 11:45 AM · uistartupscript loading

UI hierarchy: How to predict the order in which Start() is called?

Hello Unity Community,

Given a hierarchy of UI elements, is there a way to change or predict the order in which Start() is called? For example: One of my Scenes has the following hierarchy:

 Scene:
 |-  Canvas
     |-  Panel Player 1
         |- Some UI elements
         |- Some UI elements
     |-  Panel Player 2
         |- Some UI elements
         |- Some UI elements
     |-  Panel Player 3
         |- Some UI elements
         |- Some UI elements
     |-  Panel Player 4
         |- Some UI elements
         |- Some UI elements

Note: "Panel Player 1-4" are four instances of a prefab.

Now, when stepping through the code, the order in which the various Start() methods are executed is:

  1. Player Panel 2

  2. Player Panel 4

  3. Player Panel 3

  4. Canvas

  5. Player Panel 1

Kinda arbitrary... isn't it? Now I'm curious what causes that order and how to change it. Is there a way to influence the order in which the Start() methods are called? Or is this a bug in Unity (5.4.1.f1)?

One thing that's remarkable is that it's always the same order. Also Start() and Awake() of both, the Canvas and the 'Panel Player 1-4', are empty (i.e. they ain't call each other). However, canvas and panels do have references assigned to each other in Unitys inspector view.

Please let me know if you have any explanation about what causes that weird execution order and how to fix it. Thank you!

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

1 Reply

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

Answer by doublemax · Oct 11, 2016 at 11:58 AM

https://docs.unity3d.com/Manual/class-ScriptExecution.html

Comment
Add comment · Show 3 · 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 Nananaaa · Oct 11, 2016 at 03:05 PM 0
Share

Thank you very much! That link explains a lot. The arbitrary script execution is an... interesting... concept. Funny enough, after specifying the script execution order, the Start() methods of the four player panels are now called twice. Need to figure out why somehow, but anyway, thank you!

avatar image doublemax Nananaaa · Oct 11, 2016 at 03:07 PM 0
Share

"arbitrary" probably means: In the physical order they are found in the filesystem.

avatar image Bonfire-Boy Nananaaa · Oct 11, 2016 at 03:49 PM 1
Share

I think it's worth saying that if the order of execution makes a difference, there's probably a better way of doing things.

If the set-up methods of UI elements (or any other GameObjects, really) are inter-dependent in some way, I$$anonymous$$O it's better to find a way of having them set each other up, or create a manager object of some sort that sets them up (in their dependent aspects, at least), rather than relying on Start() functions.

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

Trying to Get Our Resolution Settings to Start on the Current Resolution of the Player's Computer 0 Answers

RectTransform gives me different value depending on its enabled state when I hit play 0 Answers

Event function after Start? 1 Answer

Changing GUI Button Script 4 Answers

How to enable and disable raw image on ui system 3 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