fix: NetworkSceneManager clearing scene placed NetworkObjects list when ClientSynchronizationMode is additive#2383
Merged
NoelStephensUnity merged 32 commits intodevelopfrom Mar 2, 2023
Conversation
Co-authored-by: Sam Bellomo <71790295+SamuelBellomo@users.noreply.github.com>
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; |
Member
Author
There was a problem hiding this comment.
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); |
Member
Author
There was a problem hiding this comment.
Another integration test thing where we don't want to destroy the temporary prefab instance during an integration test.
samlucas-unity
approved these changes
Feb 22, 2023
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the
NetworkSceneManager.ClientSynchronizationModeis set toLoadSceneMode.Additiveand the client is being synchronized,NetworkSceneManagershould not clear its scene placed objects list as there might already be in-sceneNetworkObjects 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.ClientSynchronizationModeis set toLoadSceneMode.Additive.This also includes added
NetworkObjectscene migration synchronization capabilities that will synchronize clients when aNetworkObjectis 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
NetworkObjectto 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.ActiveSceneSynchronizationEnabledproperty, disabled by default, that enables client synchronization of server-side active scene changes.NetworkObject.ActiveSceneSynchronization, disabled by default, that will automatically migrate aNetworkObjectto a newly assigned active scene.NetworkObject.SceneMigrationSynchronization, enabled by default, that will synchronize client(s) when aNetworkObjectis migrated into a new scene on the server side viaSceneManager.MoveGameObjectToScene.Changed
NetworkSceneManagerto migrate dynamically spawnedNetworkObjects withDestroyWithSceneset to false into the active scene if their current scene is unloaded.NetworkSceneManager.ClientSynchronizationModeduring the initial client synchronization.Fixed:
NetworkSceneManager.ClientSynchronizationModeisLoadSceneMode.Additiveand 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.ClientSynchronizationModewas set toLoadSceneMode.Additive.Testing and Documentation
NetworkObjectscene migration tests)