I initially posted a question regarding this:
https://discussions.unity.com/t/scenemanager-active-scene-is-previous-scene-after-loading-and-running-new-scene/1506757/6
However after testing it just does not seem plausible that this should be occurring unless I am failing to consider something.
I am testing to see if the previous scene is unloaded and the new one is loaded and setting that to active, and it passes, yet when I use methods like:
var cutScenes = FindObjectsOfType<CutScene>();
It retrieves objects from the previous scene that I have just confirmed finished unloading and have since loaded and set active the new scene.
Lines like this hang forever while I am literally in the new scene moving around and interacting with objects in the new scene with the hierarchy, scene mode and play mode running the new scene:
// SceneManager.GetActiveScene().name returns LD03, c cutsceneData.sceneName returns LD04, active scene in hierarchy, scene and play
// mode is LD04
yield return new WaitUntil(()=>SceneManager.GetActiveScene().name == cutsceneData.sceneName);
I ended up just trying to see if synchronously loading the scene immediately would fix this and it still does not.
SceneManager.LoadScene(cutsceneData.sceneName);
The result is that it loads LD04 in editor but active scene still logs as LD03 and all methods acting on the active scene operate on LD03 which is not loaded in the editor:
I see a confirmation that LD04 is loaded from the sceneLoaded event but the coroutine still hangs on waiting for the active scene name to match LD04 it still says it’s LD03. And if I remove the while loop waiting for the condition, it will grab the objects from LD03 even though I am in LD04.
The while loop logging that LD04 is not the active scene yet only logs 5 times. So Idk if the coroutine just stops working or what is going on. I would imagine this is supposed to continue forever?
Interestingly if I load the scene asynchronously and yield return to wait for it to fully load it never does. It will get stuck there instead. Why would that occur why would the scene never finish loading?
If I change this from StartCoroutine to yield return the log statement below never logs ever:
if (cutsceneData.sceneName != SceneManager.GetActiveScene().name)
{
#if UNITY_EDITOR
Debug.Log($"MULTICUTSCENE Requesting scene change to {cutsceneData.sceneName} from {currentScene}");
#endif
AreaExit areaExit = FindObjectOfType<AreaExit>();
StartCoroutine(areaExit.ExitSceneWithoutLoadScreenUsingSaveData(cutsceneData.sceneName));
// yield return areaExit.ExitSceneWithoutLoadScreenUsingSaveDataTest(cutsceneData.sceneName);
// SceneManager.LoadScene(cutsceneData.sceneName);
// yield return new WaitUntil(() => isSceneLoaded == false);
#if UNITY_EDITOR
Debug.Log($"MULTICUTSCENE Scene change to {cutsceneData.sceneName} from {currentScene} complete");
However if I call the SceneManager from any other coroutine other than the one I am having issues with, it returns LD04, while it still returns LD03 in the said coroutine:
I can’t seem to retrieve the updated scene in the coroutine no matter what. But everywhere else if I call SceneManager.GetActiveScene.name I get the new scene simultaneously.