From 5a5218ac29dcb7afdab904b79b6607ad6fc03b57 Mon Sep 17 00:00:00 2001 From: Yonatan Tepperberg Date: Tue, 4 Aug 2020 11:25:44 +0300 Subject: [PATCH] Skip unloaded scenes Lines 1027-1029: if the scene is unloaded, do not add it to the allGo list. This allows the script to function even if there are unloaded scenes in the hierarchy. --- ResourceChecker.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ResourceChecker.cs b/ResourceChecker.cs index aa692ee..681a535 100755 --- a/ResourceChecker.cs +++ b/ResourceChecker.cs @@ -1024,7 +1024,10 @@ private static GameObject[] GetAllRootGameObjects() #else List allGo = new List(); for (int sceneIdx = 0; sceneIdx < UnityEngine.SceneManagement.SceneManager.sceneCount; ++sceneIdx){ - allGo.AddRange( UnityEngine.SceneManagement.SceneManager.GetSceneAt(sceneIdx).GetRootGameObjects().ToArray() ); + //only add the scene to the list if it's currently loaded. + if (UnityEngine.SceneManagement.SceneManager.GetSceneAt(sceneIdx).isLoaded) { + allGo.AddRange(UnityEngine.SceneManagement.SceneManager.GetSceneAt(sceneIdx).GetRootGameObjects().ToArray()); + } } allGo.AddRange(GetDontDestroyOnLoadRoots());