You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: NetworkSceneManager clearing scene placed NetworkObjects list when ClientSynchronizationMode is additive (#2383)
* fix
When the ClientSynchronizationMode is additive and the client is being synchronized, we need to not clear the ScenePlacedObjects list as there might already be ScenePlacedObjects populated.
A more robust fix for running the server-side NetworkSceneManager in client synchronization mode additive.
Fixing minor issue where AddSceneObject was always passing false for the destroy with scene parameter.
* update
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.
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.
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.
This includes the additional changes required to assure that clients are synchronized when a dynamically spawned NetworkObject is moved into a new scene.'
Updating scene manager handler to include moving objects from a scene to the DDOL (for unloading a scene only).
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.
* test
Updating existing integration tests and the additive scene loading test to be able to manually test.
The additional integration tests for this PR. (WIP)
Includes 3 additional empty scenes to verify object scene migration.
Also a minor style issue addressed in NetworkSceneManager.
Adding tests for NetworkObject scene migration.
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.
Updating the IntegrationTestSceneHandler with the recent changes to ISceneManagerHandler.
Fixing some minor issues preventing some of the manual tests from functioning properly.
Copy file name to clipboardExpand all lines: com.unity.netcode.gameobjects/CHANGELOG.md
+17-1Lines changed: 17 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,27 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
7
7
Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com).
8
-
9
8
## [Unreleased]
10
9
11
10
### Added
12
11
12
+
- Added `NetworkSceneManager.ActiveSceneSynchronizationEnabled` property, disabled by default, that enables client synchronization of server-side active scene changes. (#2383)
13
+
- Added `NetworkObject.ActiveSceneSynchronization`, disabled by default, that will automatically migrate a `NetworkObject` to a newly assigned active scene. (#2383)
14
+
- Added `NetworkObject.SceneMigrationSynchronization`, enabled by default, that will synchronize client(s) when a `NetworkObject` is migrated into a new scene on the server side via `SceneManager.MoveGameObjectToScene`. (#2383)
15
+
16
+
### Changed
17
+
18
+
- Updated `NetworkSceneManager` to migrate dynamically spawned `NetworkObject`s with `DestroyWithScene` set to false into the active scene if their current scene is unloaded. (#2383)
19
+
- Updated the server to synchronize its local `NetworkSceneManager.ClientSynchronizationMode` during the initial client synchronization. (#2383)
20
+
21
+
### Fixed
22
+
23
+
- Fixed registry of public `NetworkVariable`s in derived `NetworkBehaviour`s (#2423)
24
+
- Fixed issue when the `NetworkSceneManager.ClientSynchronizationMode` is `LoadSceneMode.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. (#2383)
25
+
- Fixed issue where a client would load duplicate scenes of already preloaded scenes during the initial client synchronization and `NetworkSceneManager.ClientSynchronizationMode` was set to `LoadSceneMode.Additive`. (#2383)
/// When set to true and the active scene is changed, this will automatically migrate the <see cref="NetworkObject"/>
110
+
/// into the new active scene on both the server and client instances.
111
+
/// </summary>
112
+
/// <remarks>
113
+
/// - This only applies to dynamically spawned <see cref="NetworkObject"/>s.
114
+
/// - This only works when using integrated scene management (<see cref="NetworkSceneManager"/>).
115
+
///
116
+
/// If there are more than one scenes loaded and the currently active scene is unloaded, then typically
117
+
/// the <see cref="SceneManager"/> will automatically assign a new active scene. Similar to <see cref="DestroyWithScene"/>
118
+
/// being set to <see cref="false"/>, this prevents any <see cref="NetworkObject"/> from being destroyed
119
+
/// with the unloaded active scene by migrating it into the automatically assigned active scene.
120
+
/// Additionally, this is can be useful in some seamless scene streaming implementations.
121
+
/// Note:
122
+
/// Only having <see cref="ActiveSceneSynchronization"/> set to true will *not* synchronize clients when
123
+
/// changing a <see cref="NetworkObject"/>'s scene via <see cref="SceneManager.MoveGameObjectToScene(GameObject, Scene)"/>.
124
+
/// To synchronize clients of a <see cref="NetworkObject"/>'s scene being changed via <see cref="SceneManager.MoveGameObjectToScene(GameObject, Scene)"/>,
125
+
/// make sure <see cref="SceneMigrationSynchronization"/> is enabled (it is by default).
126
+
/// </remarks>
127
+
publicboolActiveSceneSynchronization;
128
+
129
+
/// <summary>
130
+
/// When enabled (the default), if a <see cref="NetworkObject"/> is migrated to a different scene (active or not)
131
+
/// via <see cref="SceneManager.MoveGameObjectToScene(GameObject, Scene)"/> on the server side all client
132
+
/// instances will be synchronized and the <see cref="NetworkObject"/> migrated into the newly assigned scene.
133
+
/// The updated scene migration will get synchronized with late joining clients as well.
134
+
/// </summary>
135
+
/// <remarks>
136
+
/// - This only applies to dynamically spawned <see cref="NetworkObject"/>s.
137
+
/// - This only works when using integrated scene management (<see cref="NetworkSceneManager"/>).
138
+
/// Note:
139
+
/// You can have both <see cref="ActiveSceneSynchronization"/> and <see cref="SceneMigrationSynchronization"/> enabled.
140
+
/// The primary difference between the two is that <see cref="SceneMigrationSynchronization"/> only synchronizes clients
141
+
/// when the server migrates a <see cref="NetworkObject"/> to a new scene. If the scene is unloaded and <see cref="DestroyWithScene"/>
142
+
/// is <see cref="true"/> and <see cref="ActiveSceneSynchronization"/> is <see cref="false"/> and the scene is not the currently
143
+
/// active scene, then the <see cref="NetworkObject"/> will be destroyed.
144
+
/// </remarks>
145
+
publicboolSceneMigrationSynchronization=true;
146
+
147
+
/// <summary>
148
+
/// Notifies when the NetworkObject is migrated into a new scene
149
+
/// </summary>
150
+
/// <remarks>
151
+
/// - <see cref="ActiveSceneSynchronization"/> or <see cref="SceneMigrationSynchronization"/> (or both) need to be enabled
152
+
/// - This only applies to dynamically spawned <see cref="NetworkObject"/>s.
153
+
/// - This only works when using integrated scene management (<see cref="NetworkSceneManager"/>).
154
+
/// </remarks>
155
+
publicActionOnMigratedToNewScene;
156
+
108
157
/// <summary>
109
158
/// Delegate type for checking visibility
110
159
/// </summary>
@@ -188,6 +237,11 @@ public bool IsNetworkVisibleTo(ulong clientId)
188
237
/// </summary>
189
238
internalintSceneOriginHandle=0;
190
239
240
+
/// <summary>
241
+
/// The server-side scene origin handle
242
+
/// </summary>
243
+
internalintNetworkSceneHandle=0;
244
+
191
245
privateScenem_SceneOrigin;
192
246
/// <summary>
193
247
/// The scene where the NetworkObject was first instantiated
@@ -1118,6 +1172,18 @@ public bool WorldPositionStays
1118
1172
set=>ByteUtility.SetBit(refm_BitField,5,value);
1119
1173
}
1120
1174
1175
+
/// <summary>
1176
+
/// Even though the server sends notifications for NetworkObjects that get
1177
+
/// destroyed when a scene is unloaded, we want to synchronize this so
1178
+
/// the client side can use it as part of a filter for automatically migrating
1179
+
/// to the current active scene when its scene is unloaded. (only for dynamically spawned)
1180
+
/// </summary>
1181
+
publicboolDestroyWithScene
1182
+
{
1183
+
get=>ByteUtility.GetBit(m_BitField,6);
1184
+
set=>ByteUtility.SetBit(refm_BitField,6,value);
1185
+
}
1186
+
1121
1187
//If(Metadata.HasParent)
1122
1188
publiculongParentObjectId;
1123
1189
@@ -1160,7 +1226,7 @@ public void Serialize(FastBufferWriter writer)
0 commit comments