I have some singletons in my project that used OnLevelWasLoaded functions.
I’ve seen some workarounds but not for Singletons that have OnLevel…
Like this One: (NOT MINE)
void OnEnable()
{
//Tell our 'OnLevelFinishedLoading' function to start listening for a scene change as soon as this script is enabled.
SceneManager.sceneLoaded += OnLevelFinishedLoading;
}
void OnDisable()
{
//Tell our 'OnLevelFinishedLoading' function to stop listening for a scene change as soon as this script is disabled. Remember to always have an unsubscription for every delegate you subscribe to!
SceneManager.sceneLoaded -= OnLevelFinishedLoading;
}
void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
{
Debug.Log("Level Loaded");
Debug.Log(scene.name);
Debug.Log(mode);
}
The problem is that, It’s called several times, in scenes that it does not need to be called.
What I need is to be able to call the “OnLevelFinishedLoading” function, only in certain scenes, not in ALL of them, that is the problem with the code shown above, it’s designed for NON singleton gameobjects.
Any workaround for the Singleton gameobjects?
Thanks in advance!
-Chris