Hi guys,
I’m implementing a scene management module to load my levels in background.
The simplified situation is: I have a singleton in Scene1 that use the accessor bellow:
private static ScreenManager instance;
public static ScreenManager Instance
{
get
{
if (instance == null)
instance = FindObjectOfType<ScreenManager>();
return instance;
}
}
In Scene2, I have a GameObject that tries to access this singleton:
private void OnEnable()
{
Debug.Log(ScreenManager.Instance);
}
Scene1 loads Scene2 with the additive flag and then the object in Scene2 tries to get the singleton in Scene1.
When I have only Scene1 loaded in the editor and I hit the Play button, everything works as expected.
When I have Scene1 and Scene2 loaded in the editor and I hit the Play button, ScreenManager.Instance is Null.
Is this the expected behavior? Can I avoid using a coroutine to fix this?
Thank you for reading this!