Skip to content

Commit 2493ff6

Browse files
fix
Send InSceneNetworkObjectsSpawned and InternalNetworkSessionSynchronized NetworkBehaviour notifications on the server, host, and session owner side when first starting a session.
1 parent 90cbb1e commit 2493ff6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,17 @@ public bool StartServer()
12181218
{
12191219
SpawnManager.ServerSpawnSceneObjectsOnStartSweep();
12201220

1221+
// Notify the server that all in-scnee placed NetworkObjects are spawned at this time.
1222+
foreach (var networkObject in SpawnManager.SpawnedObjectsList)
1223+
{
1224+
networkObject.InternalInSceneNetworkObjectsSpawned();
1225+
}
1226+
1227+
// Notify the server that everything should be synchronized/spawned at this time.
1228+
foreach (var networkObject in SpawnManager.SpawnedObjectsList)
1229+
{
1230+
networkObject.InternalNetworkSessionSynchronized();
1231+
}
12211232
OnServerStarted?.Invoke();
12221233
ConnectionManager.LocalClient.IsApproved = true;
12231234
return true;
@@ -1364,6 +1375,17 @@ private void HostServerInitialize()
13641375
}
13651376

13661377
SpawnManager.ServerSpawnSceneObjectsOnStartSweep();
1378+
// Notify the host that all in-scnee placed NetworkObjects are spawned at this time.
1379+
foreach (var networkObject in SpawnManager.SpawnedObjectsList)
1380+
{
1381+
networkObject.InternalInSceneNetworkObjectsSpawned();
1382+
}
1383+
1384+
// Notify the host that everything should be synchronized/spawned at this time.
1385+
foreach (var networkObject in SpawnManager.SpawnedObjectsList)
1386+
{
1387+
networkObject.InternalNetworkSessionSynchronized();
1388+
}
13671389

13681390
OnServerStarted?.Invoke();
13691391
OnClientStarted?.Invoke();

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ConnectionApprovedMessage.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ public void Handle(ref NetworkContext context)
243243
// Spawn any in-scene placed NetworkObjects
244244
networkManager.SpawnManager.ServerSpawnSceneObjectsOnStartSweep();
245245

246+
// With scene management enabled and since the session owner doesn't send a Synchronize scene event synchronize itself,
247+
// we need to notify the session owner that all in-scnee placed NetworkObjects are spawned at this time.
248+
foreach (var networkObject in networkManager.SpawnManager.SpawnedObjectsList)
249+
{
250+
networkObject.InternalInSceneNetworkObjectsSpawned();
251+
}
252+
246253
// Spawn the local player of the session owner
247254
if (networkManager.AutoSpawnPlayerPrefabClientSide)
248255
{
@@ -252,6 +259,13 @@ public void Handle(ref NetworkContext context)
252259
// Synchronize the service with the initial session owner's loaded scenes and spawned objects
253260
networkManager.SceneManager.SynchronizeNetworkObjects(NetworkManager.ServerClientId);
254261

262+
// With scene management enabled and since the session owner doesn't send a Synchronize scene event synchronize itself,
263+
// we need to notify the session owner that everything should be synchronized/spawned at this time.
264+
foreach (var networkObject in networkManager.SpawnManager.SpawnedObjectsList)
265+
{
266+
networkObject.InternalNetworkSessionSynchronized();
267+
}
268+
255269
// When scene management is enabled and since the session owner is synchronizing the service (i.e. acting like host),
256270
// we need to locallyh invoke the OnClientConnected callback at this point in time.
257271
networkManager.ConnectionManager.InvokeOnClientConnectedCallback(OwnerClientId);

0 commit comments

Comments
 (0)