Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

New methods (start1, start2....Update1, Update2..)

Discussion in 'Editor & General Support' started by RandomCharacters, Dec 8, 2015.

  1. RandomCharacters

    RandomCharacters

    Joined:
    Nov 29, 2012
    Posts:
    262
    ...
     
    Last edited: Mar 2, 2017
  2. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    You have LateUpdate for doing things after Update. And you could make something like this yourself, I don't really see any particular reason why this needs to be built in.
     
  3. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    There's always the ability to set the script execution order in project settings as well.
     
    karl_jones likes this.
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    If you really need the scripts to execute in a specific order, you can use the script execution order to set that up.

    Usually, being dependent on the order Start is called is a sign that your stuff is too tightly coupled. A good general way to set things up is to generate every internal dependency in Awake (so GetComponent and creation of fields goes there), and then grab external dependencies (other MonoBehaviours) in Start.

    If you need more layers, then you've got something like component A depending on component C through component B. That's probably bad.

    Finally, there's also the option of making dependencies be lazy. That'll guard you against any un-initialized fields, and moves some loading from scene/object load to when the thing is needed, which is a bonus.

    Oh, and a life-protip. When you open a discussion, accusing other people of being brainwashed IN YOUR OPENING POST is not exactly the best way to win people over.
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,984
    Alternately, you could read the docs and just set things up properly:
    http://docs.unity3d.com/Manual/ExecutionOrder.html

    Hardcoding specific values to force order is a bad idea in many ways, and not really the point of those methods in the first place. If order is an issue when using start/awake, then A) consider writing more robust code to deal with whatever your dependencies are, B) create your own Init() type method and call it when is needed, C) use script order of execution as pointed out above.

    Ordering isn't an issue if you do things in logical way. If for some reason you do need ordering, just handle in the code, it is trivial. Changing the functionality of the monobehviour isn't the place to "fix" your architecture issues. And as said above, being a dick about it isn't the way to go about getting help. No one is "brainwashed", we just know what we are doing.
     
    karl_jones and Brainswitch like this.