Skip to content

Commit e9b7ef4

Browse files
fix: scene loading event not synchronizing in scene objects (#3096)
* fix This fixes the issue with in-scene placed NetworkObjects not being synchronized properly when the session owner generates a scene event type load. The service is not considered an observer and when sending a scene event type load it should send all spawned objects. * update adding changelog entry * update adding associated PR to changelog entry * update covering synchronization too.
1 parent 0055e1c commit e9b7ef4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1818

1919
### Fixed
2020

21+
- Fixed issue with service not getting synchronized with in-scene placed `NetworkObject` instances when a session owner starts a `SceneEventType.Load` event. (#3096)
2122
- Fixed issue with the in-scene network prefab instance update menu tool where it was not properly updating scenes when invoked on the root prefab instance. (#3092)
2223
- Fixed issue where applying the position and/or rotation to the `NetworkManager.ConnectionApprovalResponse` when connection approval and auto-spawn player prefab were enabled would not apply the position and/or rotation when the player prefab was instantiated. (#3078)
2324
- Fixed issue where `NetworkObject.SpawnWithObservers` was not being honored when spawning the player prefab. (#3077)

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ private void SortParentedNetworkObjects()
320320
internal void AddSpawnedNetworkObjects()
321321
{
322322
m_NetworkObjectsSync.Clear();
323+
// If distributed authority mode and sending to the service, then ignore observers
324+
var distributedAuthoritySendingToService = m_NetworkManager.DistributedAuthorityMode && TargetClientId == NetworkManager.ServerClientId;
323325
foreach (var sobj in m_NetworkManager.SpawnManager.SpawnedObjectsList)
324326
{
325-
if (sobj.Observers.Contains(TargetClientId))
327+
if (sobj.Observers.Contains(TargetClientId) || distributedAuthoritySendingToService)
326328
{
327329
m_NetworkObjectsSync.Add(sobj);
328330
}
@@ -666,12 +668,14 @@ internal void SerializeScenePlacedObjects(FastBufferWriter writer)
666668
// Write our count place holder (must not be packed!)
667669
writer.WriteValueSafe((ushort)0);
668670
var distributedAuthority = m_NetworkManager.DistributedAuthorityMode;
671+
// If distributed authority mode and sending to the service, then ignore observers
672+
var distributedAuthoritySendingToService = distributedAuthority && TargetClientId == NetworkManager.ServerClientId;
669673

670674
foreach (var keyValuePairByGlobalObjectIdHash in m_NetworkManager.SceneManager.ScenePlacedObjects)
671675
{
672676
foreach (var keyValuePairBySceneHandle in keyValuePairByGlobalObjectIdHash.Value)
673677
{
674-
if (keyValuePairBySceneHandle.Value.Observers.Contains(TargetClientId))
678+
if (keyValuePairBySceneHandle.Value.Observers.Contains(TargetClientId) || distributedAuthoritySendingToService)
675679
{
676680
// Serialize the NetworkObject
677681
var sceneObject = keyValuePairBySceneHandle.Value.GetMessageSceneObject(TargetClientId, distributedAuthority);

0 commit comments

Comments
 (0)