@@ -33,7 +33,7 @@ public static class NetworkSceneManager
33
33
internal static readonly Dictionary < uint , string > sceneIndexToString = new Dictionary < uint , string > ( ) ;
34
34
internal static readonly Dictionary < Guid , SceneSwitchProgress > sceneSwitchProgresses = new Dictionary < Guid , SceneSwitchProgress > ( ) ;
35
35
private static Scene lastScene ;
36
- private static Scene nextScene ;
36
+ private static string nextSceneName ;
37
37
private static bool isSwitching = false ;
38
38
internal static uint currentSceneIndex = 0 ;
39
39
internal static Guid currentSceneSwitchProgressGuid = new Guid ( ) ;
@@ -88,9 +88,8 @@ public static SceneSwitchProgress SwitchScene(string sceneName)
88
88
89
89
// Switch scene
90
90
AsyncOperation sceneLoad = SceneManager . LoadSceneAsync ( sceneName , LoadSceneMode . Single ) ;
91
-
92
- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
93
-
91
+ nextSceneName = sceneName ;
92
+
94
93
sceneLoad . completed += ( AsyncOperation asyncOp2 ) => { OnSceneLoaded ( switchSceneProgress . guid , null ) ; } ;
95
94
96
95
switchSceneProgress . SetSceneLoadOperation ( sceneLoad ) ;
@@ -121,9 +120,8 @@ internal static void OnSceneSwitch(uint sceneIndex, Guid switchSceneGuid, Stream
121
120
string sceneName = sceneIndexToString [ sceneIndex ] ;
122
121
123
122
AsyncOperation sceneLoad = SceneManager . LoadSceneAsync ( sceneName , LoadSceneMode . Single ) ;
124
-
125
- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
126
-
123
+ nextSceneName = sceneName ;
124
+
127
125
sceneLoad . completed += ( AsyncOperation asyncOp2 ) =>
128
126
{
129
127
OnSceneLoaded ( switchSceneGuid , objectStream ) ;
@@ -144,7 +142,7 @@ internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGui
144
142
145
143
lastScene = SceneManager . GetActiveScene ( ) ;
146
144
string sceneName = sceneIndexToString [ sceneIndex ] ;
147
- nextScene = SceneManager . GetSceneByName ( sceneName ) ;
145
+ nextSceneName = sceneName ;
148
146
CurrentActiveSceneIndex = sceneNameToIndex [ sceneName ] ;
149
147
150
148
isSpawnedObjectsPendingInDontDestroyOnLoad = true ;
@@ -164,7 +162,8 @@ internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGui
164
162
165
163
private static void OnSceneLoaded ( Guid switchSceneGuid , Stream objectStream )
166
164
{
167
- CurrentActiveSceneIndex = sceneNameToIndex [ nextScene . name ] ;
165
+ CurrentActiveSceneIndex = sceneNameToIndex [ nextSceneName ] ;
166
+ Scene nextScene = SceneManager . GetSceneByName ( nextSceneName ) ;
168
167
SceneManager . SetActiveScene ( nextScene ) ;
169
168
170
169
// Move all objects to the new scene
0 commit comments