I have a GameScene
with an initially active GameObject
in it, which has a singleton component:
public static ObjectiveManager Instance;
public void Awake()
{
if (Instance != null && Instance != this)
{
Log.Info(this.GetType(), "Instance of this class already exists! CRITICAL");
}
ObjectiveManager.Instance = this;
}
Now, when I call:
private void StartGameScene(){
SceneManager.LoadScene("GameScene");
ObjectiveManager.Instance.SomeFunction(); // << singleton not initialized
}
I get an error, because ObjectiveManager
is not set to an instance of an object.
As LoadScene
is a synchronous operation so my guess was that Awake()
is called immediately, synchronously. As I can see now, it's not.
Is there any way to determine that all of the objects on the scene have their Awake()
already called, without checking each of them with some custom IsReady
?