Skip to content

Commit

Permalink
fix: scenemanager clean up ScenesLoaded after synch unloading of rema…
Browse files Browse the repository at this point in the history
…ining 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
  • Loading branch information
NoelStephensUnity authored Jul 18, 2024
1 parent 7915bd4 commit f0db817
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- Fixed issue where `NetworkManager.ScenesLoaded` was not being updated if `PostSynchronizationSceneUnloading` was set and any loaded scenes not used during synchronization were unloaded.(#2977)
- 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)
- Fixed issue with the client count not being correct on the host or server side when a client disconnects itself from a session. (#2941)
- Fixed issue with the host trying to send itself a message that it has connected when first starting up. (#2941)
Expand All @@ -24,7 +25,6 @@ Additional documentation and release notes are available at [Multiplayer Documen
- 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)
- 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)


### Changed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ public void UnloadUnassignedScenes(NetworkManager networkManager = null)
foreach (var sceneToUnload in m_ScenesToUnload)
{
SceneManager.UnloadSceneAsync(sceneToUnload);
// Update the ScenesLoaded when we unload scenes
if (sceneManager.ScenesLoaded.ContainsKey(sceneToUnload.handle))
{
sceneManager.ScenesLoaded.Remove(sceneToUnload.handle);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ public void UnloadUnassignedScenes(NetworkManager networkManager = null)
foreach (var sceneToUnload in m_ScenesToUnload)
{
SceneManager.UnloadSceneAsync(sceneToUnload.Key);
// Update the ScenesLoaded when we unload scenes
if (sceneManager.ScenesLoaded.ContainsKey(sceneToUnload.Key.handle))
{
sceneManager.ScenesLoaded.Remove(sceneToUnload.Key.handle);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,26 @@ public IEnumerator SceneVerifyBeforeLoadTest()

m_IsTestingVerifyScene = false;
Assert.AreEqual(m_ServerNetworkManager.SceneManager.UnloadScene(m_CurrentScene), SceneEventProgressStatus.Started);

var currentSceneName = m_CurrentScene;
// Now wait for scenes to unload
yield return WaitForConditionOrTimeOut(ConditionPassed);
AssertOnTimeout($"Timed out waiting for all clients to unload {m_CurrentSceneName}!\n{PrintFailedCondition()}");

// Verify that all NetworkSceneManager instances reflect the change in scenes synchronized
var scenesSynchronized = m_ServerNetworkManager.SceneManager.ScenesLoaded;
foreach (var scene in scenesSynchronized)
{
Assert.False(scene.Value.name.Equals(currentSceneName), $"Host still thinks scene {currentSceneName} is loaded and synchronized!");
}

foreach (var client in m_ClientNetworkManagers)
{
scenesSynchronized = client.SceneManager.ScenesLoaded;
foreach (var scene in scenesSynchronized)
{
Assert.False(scene.Value.name.Equals(currentSceneName), $"Client-{client.LocalClientId} still thinks scene {currentSceneName} is loaded and synchronized!");
}
}
}
}
}

0 comments on commit f0db817

Please # to comment.