Let me explain,
I have a GameStates manager which acts as an FSM to control each state of the game. When the FSM starts, it first runs the “Initialize” state in which I call a function that does some initialization and sends messages to other Managers to tell them it’s time to cache some references to other things.
If the initialization was successful, GameStates then sets a static boolean to true: intiDone = true, and switches to the next state, Playing.
Now my other classes rely on initDone to set themselves up. The problem is that sometimes, initDone only becomes true after Update() in those classes, and Update() uses variables that get set when initDone becomes true.
So 1 solution is to use: if( initDone == false ) return; - in Update(), but it seems like a waste of time because it’s always gonna have to check it before continuing.
The other solution i thought about is instead of using Update(), I would use a coroutine, that way when initDone = true, I can send a Message to all classes that are waiting for it, and start the coroutine in each class. The coroutine would run every frame just like Update().
But, I couldn’t do that for FixedUpdate(), since physics should be in FixedUpdate I cannot have a coroutine running my physics calculations.
I am running into this problem a lot because of the OnEnable() bug which force the class it belongs to to execute before any other class which doesn’t have OnEnable() defined. The whole idea behind my GameStates class was to control these kind of things, and it worked great until I started using LoadLevelAdditive() to load things like HUD, Controls and Player into each scene, instead of having to manually place them into each new scene I create.
Since those classes are being loaded after the current’s scene classes, it broke my GameStates logic and I am now trying to make it work with classes that come in after the initialization.
Sorry for the long post, and thanks in advance for your time! If anyone could maybe give me some advice I would really appreciate it
Thanks guys,
Stephane