Start() sequence

i have a structure consisting of a couple of hierarchically arranged game objects. Like so:

Base
   TriggerA
   TriggerB
   UI
   Lines

etc.

Now the “Base” object holds the main variables and functions of the whole construct, so i want to reference it occationally in the child-objects and vice versa.

For example I’d do this on a child:

private var baseScriptRef;

function Start() {
    baseScriptRef = transform.parent.GetComponent("baseScript");
}

function OnGUI () {
    print(baseScriptRef.foo);
}

Problem now is, that i cannot predict the sequence by which these Object’s “Start()” get invoked… which means i get a lot of “Object reference not set to an instance of an object” when i access a variable in “baseScript” that gets “setup” by the Start() function in that “baseScript”. So far the only workaround is a “complicated” checking routine in Update()… but i’m sure there is another way to control the sequence objects are loaded, or i’m missing something obvious…

Any ideas?

In cases like that, instead of relying on Start(), I use a Startup() function instead that doesn’t run automatically, but is called manually by a manager object. Depending on the situation, you may be able to use Awake (which always runs before Start).

–Eric