Skip to content

Commit f0db817

Browse files
fix: scenemanager clean up ScenesLoaded after synch unloading of remaining scenes not used [back port] (#2977)
* fix remove the scene from the scenesLoaded dictionary when there are remaining scenes to be unloaded. * test back ported test updates * update Adding change log entry
1 parent 7915bd4 commit f0db817

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1515

1616
### Fixed
1717

18+
- Fixed issue where `NetworkManager.ScenesLoaded` was not being updated if `PostSynchronizationSceneUnloading` was set and any loaded scenes not used during synchronization were unloaded.(#2977)
1819
- Fixed issue where internal delta serialization could not have a byte serializer defined when serializing deltas for other types. Added `[GenerateSerializationForType(typeof(byte))]` to both the `NetworkVariable` and `AnticipatedNetworkVariable` classes to assure a byte serializer is defined. (#2953)
1920
- Fixed issue with the client count not being correct on the host or server side when a client disconnects itself from a session. (#2941)
2021
- Fixed issue with the host trying to send itself a message that it has connected when first starting up. (#2941)
@@ -24,7 +25,6 @@ Additional documentation and release notes are available at [Multiplayer Documen
2425
- Fixed issue where a `NetworkObject` component's associated `NetworkBehaviour` components would not be detected if scene loading is disabled in the editor and the currently loaded scene has in-scene placed `NetworkObject`s. (#2906)
2526
- Fixed issue where an in-scene placed `NetworkObject` with `NetworkTransform` that is also parented under a `GameObject` would not properly synchronize when the parent `GameObject` had a world space position other than 0,0,0. (#2895)
2627

27-
2828
### Changed
2929

3030

com.unity.netcode.gameobjects/Runtime/SceneManagement/DefaultSceneManagerHandler.cs

+5
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ public void UnloadUnassignedScenes(NetworkManager networkManager = null)
226226
foreach (var sceneToUnload in m_ScenesToUnload)
227227
{
228228
SceneManager.UnloadSceneAsync(sceneToUnload);
229+
// Update the ScenesLoaded when we unload scenes
230+
if (sceneManager.ScenesLoaded.ContainsKey(sceneToUnload.handle))
231+
{
232+
sceneManager.ScenesLoaded.Remove(sceneToUnload.handle);
233+
}
229234
}
230235
}
231236

com.unity.netcode.gameobjects/TestHelpers/Runtime/IntegrationTestSceneHandler.cs

+5
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ public void UnloadUnassignedScenes(NetworkManager networkManager = null)
675675
foreach (var sceneToUnload in m_ScenesToUnload)
676676
{
677677
SceneManager.UnloadSceneAsync(sceneToUnload.Key);
678+
// Update the ScenesLoaded when we unload scenes
679+
if (sceneManager.ScenesLoaded.ContainsKey(sceneToUnload.Key.handle))
680+
{
681+
sceneManager.ScenesLoaded.Remove(sceneToUnload.Key.handle);
682+
}
678683
}
679684
}
680685

testproject/Assets/Tests/Runtime/NetworkSceneManager/NetworkSceneManagerSeneVerification.cs

+17-1
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,26 @@ public IEnumerator SceneVerifyBeforeLoadTest()
360360

361361
m_IsTestingVerifyScene = false;
362362
Assert.AreEqual(m_ServerNetworkManager.SceneManager.UnloadScene(m_CurrentScene), SceneEventProgressStatus.Started);
363-
363+
var currentSceneName = m_CurrentScene;
364364
// Now wait for scenes to unload
365365
yield return WaitForConditionOrTimeOut(ConditionPassed);
366366
AssertOnTimeout($"Timed out waiting for all clients to unload {m_CurrentSceneName}!\n{PrintFailedCondition()}");
367+
368+
// Verify that all NetworkSceneManager instances reflect the change in scenes synchronized
369+
var scenesSynchronized = m_ServerNetworkManager.SceneManager.ScenesLoaded;
370+
foreach (var scene in scenesSynchronized)
371+
{
372+
Assert.False(scene.Value.name.Equals(currentSceneName), $"Host still thinks scene {currentSceneName} is loaded and synchronized!");
373+
}
374+
375+
foreach (var client in m_ClientNetworkManagers)
376+
{
377+
scenesSynchronized = client.SceneManager.ScenesLoaded;
378+
foreach (var scene in scenesSynchronized)
379+
{
380+
Assert.False(scene.Value.name.Equals(currentSceneName), $"Client-{client.LocalClientId} still thinks scene {currentSceneName} is loaded and synchronized!");
381+
}
382+
}
367383
}
368384
}
369385
}

0 commit comments

Comments
 (0)