Search Unity

Start Order between GameObjects ? Start Order between several scripts within a GameObject?

Discussion in 'Scripting' started by jonbinliu, Oct 30, 2014.

  1. jonbinliu

    jonbinliu

    Joined:
    Jul 9, 2014
    Posts:
    3
    Hi , I'm curious about the Start order between several scripts within a GameObject and the Start order between GameObjects. So I did a little experiment,and then I found:

    Unity may be use STACK to manage Scripts and GameObjects. In a GameObject ,the LAST script added to GameObject will be exectue FIRST. So do GameObject.

    Did I get it wrong?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    The order in which Start, Update and all the other methods are called in is undocumented, and pretty arbitrary. The general tip is to never, ever base your code around the order in which start is called. I mean, yes it might be that the order added is the order used, but you're never guaranteed that it'll be the same order in the next version.

    Rather, use Awake and Start when things have to happen in order, or if you need a larger, ordered system, use a controller object that initializes the other ones.
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
  4. jonbinliu

    jonbinliu

    Joined:
    Jul 9, 2014
    Posts:
    3
    yes,you're right ,thanks a lot
     
  5. jonbinliu

    jonbinliu

    Joined:
    Jul 9, 2014
    Posts:
    3