Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions com.unity.netcode.gameobjects/Runtime/Core/FindObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ private struct ObjectsInSceneEnumerator<T> : IEnumerable<T>, IEnumerator<T> wher
internal ObjectsInSceneEnumerator(Scene scene, bool includeInactive)
{
m_IncludeInactive = includeInactive;

m_RootObjects = scene.GetRootGameObjects();
// If the scene is invalid, use an empty array.
m_RootObjects = scene.IsValid() ? scene.GetRootGameObjects() : new UnityEngine.GameObject[0];
m_RootIndex = 0;
m_CurrentChildObjects = null;
m_CurrentChildIndex = 0;
Expand Down
28 changes: 21 additions & 7 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2971,17 +2971,31 @@ internal void SynchronizeOwnerNetworkVariables(ulong originalOwnerId, ulong orig
childBehaviour.MarkOwnerReadDirtyAndCheckOwnerWriteIsDirty();
}

// If the spawn authority of a distributed authority network topology has invoked a change in ownership,
// then we want to invoke the NetworkBehaviourUpdate prior to changing the owner back.
if (NetworkManager.DistributedAuthorityMode)
{
// Force send a state update for all owner read NetworkVariables and any currently dirty
// owner write NetworkVariables.
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
}

// Now set the new owner and previous owner identifiers back to their original new values
// before we run the NetworkBehaviourUpdate. For owner read only permissions this order of
// operations is **particularly important** as we need to first (above) mark things as dirty
// from the context of the original owner and then second (below) we need to send the messages
// which requires the new owner to be set for owner read permission NetworkVariables.
// after we run the NetworkBehaviourUpdate.
OwnerClientId = currentOwnerId;
PreviousOwnerId = originalOwnerId;

// Force send a state update for all owner read NetworkVariables and any currently dirty
// owner write NetworkVariables.
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
// For owner read only permissions this order of operations is **particularly important** as
// we need to first (above) mark things as dirty from the context of the original owner and
// then second (below) we need to send the messages which requires the new owner to be set.
// Note: Owner read only NetworkVariables do not make sense in a distributed authority topology
// since the only instance that can write is the owner.
if (!NetworkManager.DistributedAuthorityMode)
{
// Force send a state update for all owner read NetworkVariables and any currently dirty
// owner write NetworkVariables.
NetworkManagerOwner.BehaviourUpdater.NetworkBehaviourUpdate(true);
}
}

// NGO currently guarantees that the client will receive spawn data for all objects in one network tick.
Expand Down