Skip to content

Commit a1bdccd

Browse files
fix
Fixing an order of operations issue with synchronizing owner read permission NetworkVariables.
1 parent 06bc66f commit a1bdccd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,13 +2588,18 @@ internal void SynchronizeOwnerNetworkVariables(ulong originalOwnerId, ulong orig
25882588
{
25892589
ChildNetworkBehaviours[i].MarkOwnerReadDirtyAndCheckOwnerWriteIsDirty();
25902590
}
2591-
// Force send a state update for all owner read NetworkVariables
2592-
// and any currently dirty owner write NetworkVariables.
2593-
NetworkManager.BehaviourUpdater.NetworkBehaviourUpdate(true);
2594-
// Now set the new owner identifier back to its original new owner identifier and
2595-
// set the previous owner back to the original owner identifier.
2591+
2592+
// Now set the new owner and previous owner identifiers back to their original new values
2593+
// before we run the NetworkBehaviourUpdate. For owner read only permissions this order of
2594+
// operations is **particularly important** as we need to first (above) mark things as dirty
2595+
// from the context of the original owner and then second (below) we need to send the messages
2596+
// which requires the new owner to be set for owner read permission NetworkVariables.
25962597
OwnerClientId = currentOwnerId;
25972598
PreviousOwnerId = originalOwnerId;
2599+
2600+
// Force send a state update for all owner read NetworkVariables and any currently dirty
2601+
// owner write NetworkVariables.
2602+
NetworkManager.BehaviourUpdater.NetworkBehaviourUpdate(true);
25982603
}
25992604

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

0 commit comments

Comments
 (0)