Hi, I have three classes I want initialize in order. The classes are Generator, Behaviour and Player.
These 3 objects are in the scene but I don’t what is the creating order. When I execute the project It brings me an error because Behaviour is calling Generator when Generator is not created yet.
Behaviour needs Generator instance and Player needs Behaviour instance.
To solve out I kept empty the Start method of Generator and Behaviour classes.
Then, I created a new Method called Init() in both classes and I put the code to execute there.
In Player class, in the Start method, I execute:
generator = FindObjectByType(typeof(Generator));
behaviour = FindObjectByType(typeof(Behaviour));
generator.Init();
behaviour.init(generator.getMatrix());
In this way I am sure the classes are creating in the order I need.
Is this correct? Exist a better way? I know FindObjectByType is very expensive.