@@ -33,7 +33,7 @@ public static class NetworkSceneManager
3333 internal static readonly Dictionary < uint , string > sceneIndexToString = new Dictionary < uint , string > ( ) ;
3434 internal static readonly Dictionary < Guid , SceneSwitchProgress > sceneSwitchProgresses = new Dictionary < Guid , SceneSwitchProgress > ( ) ;
3535 private static Scene lastScene ;
36- private static Scene nextScene ;
36+ private static string nextSceneName ;
3737 private static bool isSwitching = false ;
3838 internal static uint currentSceneIndex = 0 ;
3939 internal static Guid currentSceneSwitchProgressGuid = new Guid ( ) ;
@@ -88,9 +88,8 @@ public static SceneSwitchProgress SwitchScene(string sceneName)
8888
8989 // Switch scene
9090 AsyncOperation sceneLoad = SceneManager . LoadSceneAsync ( sceneName , LoadSceneMode . Single ) ;
91-
92- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
93-
91+ nextSceneName = sceneName ;
92+
9493 sceneLoad . completed += ( AsyncOperation asyncOp2 ) => { OnSceneLoaded ( switchSceneProgress . guid , null ) ; } ;
9594
9695 switchSceneProgress . SetSceneLoadOperation ( sceneLoad ) ;
@@ -121,9 +120,8 @@ internal static void OnSceneSwitch(uint sceneIndex, Guid switchSceneGuid, Stream
121120 string sceneName = sceneIndexToString [ sceneIndex ] ;
122121
123122 AsyncOperation sceneLoad = SceneManager . LoadSceneAsync ( sceneName , LoadSceneMode . Single ) ;
124-
125- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
126-
123+ nextSceneName = sceneName ;
124+
127125 sceneLoad . completed += ( AsyncOperation asyncOp2 ) =>
128126 {
129127 OnSceneLoaded ( switchSceneGuid , objectStream ) ;
@@ -144,7 +142,7 @@ internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGui
144142
145143 lastScene = SceneManager . GetActiveScene ( ) ;
146144 string sceneName = sceneIndexToString [ sceneIndex ] ;
147- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
145+ nextSceneName = sceneName ;
148146 CurrentActiveSceneIndex = sceneNameToIndex [ sceneName ] ;
149147
150148 isSpawnedObjectsPendingInDontDestroyOnLoad = true ;
@@ -164,7 +162,8 @@ internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGui
164162
165163 private static void OnSceneLoaded ( Guid switchSceneGuid , Stream objectStream )
166164 {
167- CurrentActiveSceneIndex = sceneNameToIndex [ nextScene . name ] ;
165+ CurrentActiveSceneIndex = sceneNameToIndex [ nextSceneName ] ;
166+ Scene nextScene = SceneManager . GetSceneByName ( nextSceneName ) ;
168167 SceneManager . SetActiveScene ( nextScene ) ;
169168
170169 // Move all objects to the new scene
0 commit comments