Skip to content

Commit a8e6c03

Browse files
fix
Fixing issue where we need to reset the OwnerId and PreviousOwnerId after running through NetworkBehaviourUpdate to assure the values are properly set when there are no dirty objects to reset.
1 parent ce57953 commit a8e6c03

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ internal void NetworkBehaviourUpdate(bool forceSend = false)
108108
foreach (var dirtyobj in m_DirtyNetworkObjects)
109109
{
110110
dirtyobj.PostNetworkVariableWrite(forceSend);
111-
// If we are force sending, then we are changing ownership and making sure that we
112-
// do a full synchronization of NetworkVariables.
113-
if (forceSend)
114-
{
115-
// Once done processing, we set the previous owner id to the current owner id
116-
dirtyobj.PreviousOwnerId = dirtyobj.OwnerClientId;
117-
}
118111
}
119112
m_DirtyNetworkObjects.Clear();
120113
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,13 +2591,10 @@ internal void SynchronizeOwnerNetworkVariables(ulong originalOwnerId, ulong orig
25912591
// Force send a state update for all owner read NetworkVariables
25922592
// and any currently dirty owner write NetworkVariables.
25932593
NetworkManager.BehaviourUpdater.NetworkBehaviourUpdate(true);
2594-
// Now set the new owner identifier back to its original new owner identifier
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.
25952596
OwnerClientId = currentOwnerId;
2596-
// The previous owner should now be the originalOwnerId at this point.
2597-
if (PreviousOwnerId != originalOwnerId)
2598-
{
2599-
Debug.LogError($"[NetworkVaraible][Full Synchronization] Expected {nameof(PreviousOwnerId)} ({PreviousOwnerId}) to be the original owner id ({originalOwnerId})!");
2600-
}
2597+
PreviousOwnerId = originalOwnerId;
26012598
}
26022599

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

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,9 @@ internal void ChangeOwnership(NetworkObject networkObject, ulong clientId, bool
558558
// Always notify locally on the server when a new owner is assigned
559559
networkObject.InvokeBehaviourOnGainedOwnership();
560560

561-
if (networkObject.PreviousOwnerId == NetworkManager.LocalClientId)
561+
// If we are the original owner, then we want to synchronize owner read & write NetworkVariables.
562+
if (originalOwner == NetworkManager.LocalClientId)
562563
{
563-
// Mark any owner read variables as dirty
564564
networkObject.SynchronizeOwnerNetworkVariables(originalOwner, originalPreviousOwnerId);
565565
}
566566

0 commit comments

Comments
 (0)