Search Unity

When is Start on script instantiated game objects run?

Discussion in 'Scripting' started by Marc, May 7, 2008.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    If i instantiate a game object like this

    Code (csharp):
    1.  
    2.  
    3. void Start() {
    4.  
    5.    GameObject go = new GameObject();
    6.  
    7.    MyScript ms = (MyScript)go.AddComponent(typeof(MyScript));
    8.  
    9.    ms.anInt = 2;
    10.  
    11.    ms.SomeFunction();
    12.  
    13. }
    14.  
    15.  
    When is the MyScript Start() method run? Before or after SomeFunction is executed?

    Regards,
    Marc
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775