instatiation order of events

I am building a game that does on the fly creation of the world at the beginning of each level (I am living with the lag time of creating, and destroying objects on the fly, and since it is for PC it is acceptable). I have prefabs that have children with scripts that will instantiate other GameObjects in their Awake() (work around for nested prefabs, and some functionality), and then logs that gameObject for referencing/tracking/bookKeeping.

If I have a script classA that Instantiates an object thingB at lineX will the scripts attached to thingB have their Awake/constructor methods called before lineX+1 of classA is processed so that I can access members of those scripts attached to thingB, or will I have to do that in a different place (like having all of these things created in classA Awake, and then start accessing those members in classA Start)?

When in doubt, test. It should be pretty straightforward to write a pair of classes:

  • TestChild logs its Start() and Awake() calls.
  • TestParent logs messages before and after creating a TestChild instance.
  • Attach a TestParent in your scene, and observe the logging order.

Most important: is the order of events reliable?

If you absolutely need a particular object to initialize immediately, why not write some code to make sure that happens? There are a few ways you could accomplish that:

  • Use some “lazy initialization” pattern, so that the object always initializes itself the first time anything accesses its data members.
  • Expose a function in your child class, such that the parent can immediately call it when creating its child.