-
Notifications
You must be signed in to change notification settings - Fork 457
fix: NetworkSceneManager clearing scene placed NetworkObjects list when ClientSynchronizationMode is additive #2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: NetworkSceneManager clearing scene placed NetworkObjects list when ClientSynchronizationMode is additive #2383
Conversation
Co-authored-by: Sam Bellomo <[email protected]>
Adding a piece to the puzzle where a client has scenes that don't need to be loaded or is disconnected, scenes are still loaded, and some short period later reconnects but certain scenes on the server-side are no longer loaded... under this scenario the client side will unload those scenes. Still figuring out how to best distinguish between scenes you want to keep loaded but don't get synchronized and those that do get synchronized and you do want to unload.
Auto scene migration for don't destroy with scene (migrates to the currently active scene when the scene is unloaded) and added auto active scene synchronization where, when set, they automatically migrate into the new active scene. Includes auto-scene synchronization for late joining clients and dynamically spawned NetworkObjects.
some minor adjustments due to changes. Removed the scene migration in spawn as it ended up not really making sense to do it during spawn (i.e. synchronization already handles this and if active scene synchronization is enabled then connected clients will spawn in the proper scene already). Added some missed asserts on time out to the parent dynamic under inscene placed test and removed a section of initialization code no longer needed.
After some deliberation over whether to include this update, I decided it would make more sense to include full NetworkObject scene migration synchronization. This includes the additional changes required to assure that clients are synchronized when a dynamically spawned NetworkObject is moved into a new scene.
Adding tests for NetworkObject scene migration. Updating scene manager handler to include moving objects from a scene to the DDOL (for unloading a scene only). Fixing minor issue where AddSceneObject was always passing false for the destroy with scene parameter.
Added last test, ClientSynchronizationModeTests, for this PR that validates preloaded scenes will be used and in-scene placed NetworkObjects will be synchronized even when the active scene changes which could change the order in which scenes are loaded and synchronized. This includes minor adjustments to one of the existing test. This includes the additional INetworkSceneManager.SetClientSynchronizationMode method that now builds a list of preloaded scenes if the client synchronization mode is additive. Making the parent dynamic under inscene placed run in client synchronization additive mode again.
{ | ||
// Disable resynchronization for this test to avoid issues with trying | ||
// to synchronize them. | ||
NetworkSceneManager.DisableReSynchronization = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is integration test specific and is not needed under normal operating conditions (i.e. runtime or in editor).
// Now change the active scene | ||
SceneManager.SetActiveScene(m_ScenesLoaded[1]); | ||
// We have to do this | ||
Object.DontDestroyOnLoad(m_TestPrefabAutoSynchActiveScene); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another integration test thing where we don't want to destroy the temporary prefab instance during an integration test.
com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs
Show resolved
Hide resolved
Migrating last PRs changelog into the Unreleased section.
Fixing an issue when ClientSynchronizationMode is LoadSceneMode.Single and the scene to be loaded is the primary scene and is already loaded on the client side. Caught this issue running the manual test: PreserveNetworkObjectsOnShutdown. Migrating the "shouldPassThrough" logic to the handler as this behavior/logic is slightly different when integration testing due to the fact that there can only be one active scene during an integration test.
When the
NetworkSceneManager.ClientSynchronizationMode
is set toLoadSceneMode.Additive
and the client is being synchronized,NetworkSceneManager
should not clear its scene placed objects list as there might already be in-sceneNetworkObject
s populated. This can happen if the default active scene is already loaded on the host and client(s) side and before one or more client(s) connect the active scene gets changed on the server side.Pertains to #2377
MTT-3363
MTT-5356
This also resolves issues related to seamless scene transitions and scene streaming related issues when the
NetworkSceneManager.ClientSynchronizationMode
is set toLoadSceneMode.Additive
.This also includes added
NetworkObject
scene migration synchronization capabilities that will synchronize clients when aNetworkObject
is migrated to a different scene as well as synchronizes late joining clients.This also includes the ability to synchronize clients when the currently active scene is changed on the server side along with the ability to set a
NetworkObject
to auto-synchronize itself with the change (i.e. automatically migrates to the new active scene).Internal Companion Project: This project demonstrates the various fixes and additions related to this PR.
Changelog
Added
NetworkSceneManager.ActiveSceneSynchronizationEnabled
property, disabled by default, that enables client synchronization of server-side active scene changes.NetworkObject.ActiveSceneSynchronization
, disabled by default, that will automatically migrate aNetworkObject
to a newly assigned active scene.NetworkObject.SceneMigrationSynchronization
, enabled by default, that will synchronize client(s) when aNetworkObject
is migrated into a new scene on the server side viaSceneManager.MoveGameObjectToScene
.Changed
NetworkSceneManager
to migrate dynamically spawnedNetworkObject
s withDestroyWithScene
set to false into the active scene if their current scene is unloaded.NetworkSceneManager.ClientSynchronizationMode
during the initial client synchronization.Fixed:
NetworkSceneManager.ClientSynchronizationMode
isLoadSceneMode.Additive
and the server changes the currently active scene prior to a client connecting then upon a client connecting and being synchronized the NetworkSceneManager would clear its internal ScenePlacedObjects list that could already be populated.NetworkSceneManager.ClientSynchronizationMode
was set toLoadSceneMode.Additive
.Testing and Documentation
NetworkObject
scene migration tests)