From cd62a8b9bfcbf484a57222945bc559bf022c5d8d Mon Sep 17 00:00:00 2001 From: "unity-renovate[bot]" <120015202+unity-renovate[bot]@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:07:10 +0200 Subject: [PATCH 1/7] chore(deps): update dependency recipeengine.modules.wrench to 0.11.3 (develop-2.0.0) (#3499) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | RecipeEngine.Modules.Wrench | nuget | patch | `0.11.2` -> `0.11.3` | --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Unity Renovate Bot](https://internaldocs.unity.com/renovate/). ## Backport https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/3498 Co-authored-by: unity-renovate[bot] <120015202+unity-renovate[bot]@users.noreply.github.com> From cf917e18b0d15bebec2650f0d21a4361696c0c1d Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 13 Jun 2025 17:09:14 -0400 Subject: [PATCH 2/7] fix: Avoid throwing exception when using NetworkList without a NetworkManager --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + .../NetworkVariable/Collections/NetworkList.cs | 12 ++++++------ .../Runtime/NetworkVariable/NetworkVariable.cs | 10 +++++----- .../Runtime/NetworkVariable/NetworkVariableBase.cs | 11 +++++++++++ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 7d0ec33d6f..937a0193b4 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Fixed `NullReferenceException` on `NetworkList` when used without a NetworkManager in scene. (#3503) - Fixed issue where `NetworkClient` could persist some settings if re-using the same `NetworkManager` instance. (#3491) - Fixed issue where a pooled `NetworkObject` was not resetting the internal latest parent property when despawned. (#3491) - Fixed issue where the initial client synchronization pre-serialization process was not excluding spawned `NetworkObject` instances that already had pending visibility for the client being synchronized. (#3488) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index 97fbeabc72..ebedf2ea1c 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -428,7 +428,7 @@ public IEnumerator GetEnumerator() public void Add(T item) { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return; @@ -455,7 +455,7 @@ public void Add(T item) public void Clear() { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return; @@ -493,7 +493,7 @@ public bool Contains(T item) public bool Remove(T item) { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return false; @@ -542,7 +542,7 @@ public int IndexOf(T item) public void Insert(int index, T item) { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return; @@ -578,7 +578,7 @@ public void Insert(int index, T item) public void RemoveAt(int index) { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { throw new InvalidOperationException("Client is not allowed to write to this NetworkList"); } @@ -610,7 +610,7 @@ public T this[int index] set { // check write permissions - if (!CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return; diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs index 21f92957d2..08a018b5c0 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs @@ -128,7 +128,7 @@ public virtual T Value get => m_InternalValue; set { - if (m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { LogWritePermissionError(); return; @@ -162,7 +162,7 @@ public bool CheckDirtyState(bool forceCheck = false) var isDirty = base.IsDirty(); // A client without permissions invoking this method should only check to assure the current value is equal to the last known current value - if (m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId)) + if (LocalClientCannotWrite()) { // If modifications are detected, then revert back to the last known current value if (!NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) @@ -245,7 +245,7 @@ public override bool IsDirty() { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (!NetworkUpdaterCheck && m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId) && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) + if (!NetworkUpdaterCheck && LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); return true; @@ -307,7 +307,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId) && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } @@ -349,7 +349,7 @@ public override void ReadField(FastBufferReader reader) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId) && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs index 94871ab329..84540dbd93 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; using UnityEngine; namespace Unity.Netcode @@ -381,6 +382,16 @@ public bool CanClientWrite(ulong clientId) } } + /// + /// Catches if the current is not valid to write to this variable. + /// + /// false if the current can write to this variable, true otherwise + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal bool LocalClientCannotWrite() + { + return m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId); + } + /// /// Returns the ClientId of the owning client /// From 67761bc3a8ebf02ca5ec9eb9ce77f9325ac8ff0c Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 13 Jun 2025 17:27:25 -0400 Subject: [PATCH 3/7] Update naming, add CanWrite method --- .../Messages/NetworkVariableDeltaMessage.cs | 2 +- .../NetworkVariable/AnticipatedNetworkVariable.cs | 2 +- .../NetworkVariable/Collections/NetworkList.cs | 12 ++++++------ .../Runtime/NetworkVariable/NetworkVariable.cs | 10 +++++----- .../Runtime/NetworkVariable/NetworkVariableBase.cs | 14 +++++++------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs index 05ae29b32e..c12083c5e7 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs @@ -145,7 +145,7 @@ public void Serialize(FastBufferWriter writer, int targetVersion) var networkVariable = NetworkBehaviour.NetworkVariableFields[i]; var shouldWrite = networkVariable.IsDirty() && networkVariable.CanClientRead(TargetClientId) && - (networkManager.IsServer || networkVariable.CanClientWrite(networkManager.LocalClientId)) && + (networkManager.IsServer || networkVariable.CanWrite() && networkVariable.CanSend(); // Prevent the server from writing to the client that owns a given NetworkVariable diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs index 5fe5d40818..36e0199a5a 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs @@ -217,7 +217,7 @@ public void Anticipate(T value) m_LastAnticipationCounter = m_NetworkBehaviour.NetworkManager.AnticipationSystem.AnticipationCounter; m_AnticipatedValue = value; NetworkVariableSerialization.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue); - if (CanClientWrite(m_NetworkBehaviour.NetworkManager.LocalClientId)) + if (CanWrite()) { AuthoritativeValue = value; } diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index ebedf2ea1c..3e731b4864 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -428,7 +428,7 @@ public IEnumerator GetEnumerator() public void Add(T item) { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return; @@ -455,7 +455,7 @@ public void Add(T item) public void Clear() { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return; @@ -493,7 +493,7 @@ public bool Contains(T item) public bool Remove(T item) { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return false; @@ -542,7 +542,7 @@ public int IndexOf(T item) public void Insert(int index, T item) { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return; @@ -578,7 +578,7 @@ public void Insert(int index, T item) public void RemoveAt(int index) { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { throw new InvalidOperationException("Client is not allowed to write to this NetworkList"); } @@ -610,7 +610,7 @@ public T this[int index] set { // check write permissions - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return; diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs index 08a018b5c0..19f4a3c04f 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs @@ -128,7 +128,7 @@ public virtual T Value get => m_InternalValue; set { - if (LocalClientCannotWrite()) + if (CannotWrite()) { LogWritePermissionError(); return; @@ -162,7 +162,7 @@ public bool CheckDirtyState(bool forceCheck = false) var isDirty = base.IsDirty(); // A client without permissions invoking this method should only check to assure the current value is equal to the last known current value - if (LocalClientCannotWrite()) + if (CannotWrite()) { // If modifications are detected, then revert back to the last known current value if (!NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) @@ -245,7 +245,7 @@ public override bool IsDirty() { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (!NetworkUpdaterCheck && LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) + if (!NetworkUpdaterCheck && CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); return true; @@ -307,7 +307,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } @@ -349,7 +349,7 @@ public override void ReadField(FastBufferReader reader) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (LocalClientCannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs index 84540dbd93..c8dd1801f1 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs @@ -383,14 +383,14 @@ public bool CanClientWrite(ulong clientId) } /// - /// Catches if the current is not valid to write to this variable. + /// Returns true if the current can write to this variable; otherwise false. /// - /// false if the current can write to this variable, true otherwise - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal bool LocalClientCannotWrite() - { - return m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId); - } + internal bool CanWrite => m_NetworkManager && CanClientWrite(m_NetworkManager.LocalClientId); + + /// + /// Returns false if the current can write to this variable; otherwise true. + /// + internal bool CannotWrite => m_NetworkManager && !CanClientWrite(m_NetworkManager.LocalClientId); /// /// Returns the ClientId of the owning client From 184af2ca125853bc9cd4221dba0df46d4db5dd1e Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Fri, 13 Jun 2025 16:38:41 -0500 Subject: [PATCH 4/7] style and fix Some missed parenthesis addition and removal. --- .../Messages/NetworkVariableDeltaMessage.cs | 6 +++--- .../NetworkVariable/AnticipatedNetworkVariable.cs | 2 +- .../NetworkVariable/Collections/NetworkList.cs | 12 ++++++------ .../Runtime/NetworkVariable/NetworkVariable.cs | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs index c12083c5e7..f02e2d6666 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs @@ -144,9 +144,9 @@ public void Serialize(FastBufferWriter writer, int targetVersion) var startingSize = writer.Length; var networkVariable = NetworkBehaviour.NetworkVariableFields[i]; var shouldWrite = networkVariable.IsDirty() && - networkVariable.CanClientRead(TargetClientId) && - (networkManager.IsServer || networkVariable.CanWrite() && - networkVariable.CanSend(); + networkVariable.CanClientRead(TargetClientId) + && networkManager.IsServer || + (networkVariable.CanWrite && networkVariable.CanSend()); // Prevent the server from writing to the client that owns a given NetworkVariable // Allowing the write would send an old value to the client and cause jitter diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs index 36e0199a5a..2e14bccf9c 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs @@ -217,7 +217,7 @@ public void Anticipate(T value) m_LastAnticipationCounter = m_NetworkBehaviour.NetworkManager.AnticipationSystem.AnticipationCounter; m_AnticipatedValue = value; NetworkVariableSerialization.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue); - if (CanWrite()) + if (CanWrite) { AuthoritativeValue = value; } diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index 3e731b4864..1a78fc7f81 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -428,7 +428,7 @@ public IEnumerator GetEnumerator() public void Add(T item) { // check write permissions - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return; @@ -455,7 +455,7 @@ public void Add(T item) public void Clear() { // check write permissions - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return; @@ -493,7 +493,7 @@ public bool Contains(T item) public bool Remove(T item) { // check write permissions - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return false; @@ -542,7 +542,7 @@ public int IndexOf(T item) public void Insert(int index, T item) { // check write permissions - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return; @@ -578,7 +578,7 @@ public void Insert(int index, T item) public void RemoveAt(int index) { // check write permissions - if (CannotWrite()) + if (CannotWrite) { throw new InvalidOperationException("Client is not allowed to write to this NetworkList"); } @@ -610,7 +610,7 @@ public T this[int index] set { // check write permissions - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return; diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs index 19f4a3c04f..068a6bfb68 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs @@ -128,7 +128,7 @@ public virtual T Value get => m_InternalValue; set { - if (CannotWrite()) + if (CannotWrite) { LogWritePermissionError(); return; @@ -162,7 +162,7 @@ public bool CheckDirtyState(bool forceCheck = false) var isDirty = base.IsDirty(); // A client without permissions invoking this method should only check to assure the current value is equal to the last known current value - if (CannotWrite()) + if (CannotWrite) { // If modifications are detected, then revert back to the last known current value if (!NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) @@ -245,7 +245,7 @@ public override bool IsDirty() { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (!NetworkUpdaterCheck && CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) + if (!NetworkUpdaterCheck && CannotWrite && !NetworkVariableSerialization.AreEqual(ref m_InternalValue, ref m_InternalOriginalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); return true; @@ -307,7 +307,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (CannotWrite && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } @@ -349,7 +349,7 @@ public override void ReadField(FastBufferReader reader) { // If the client does not have write permissions but the internal value is determined to be locally modified and we are applying updates, then we should revert // to the original collection value prior to applying updates (primarily for collections). - if (CannotWrite() && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) + if (CannotWrite && !NetworkVariableSerialization.AreEqual(ref m_InternalOriginalValue, ref m_InternalValue)) { NetworkVariableSerialization.Duplicate(m_InternalOriginalValue, ref m_InternalValue); } From 0a4b78cbaefe4c60d51b1be0517634c8329c68c8 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 13 Jun 2025 17:51:19 -0400 Subject: [PATCH 5/7] remove unneeded import --- .../Runtime/NetworkVariable/NetworkVariableBase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs index c8dd1801f1..8761496d2a 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using UnityEngine; namespace Unity.Netcode From 925af572145d4c7c3a8e4b885f1e54c202c27ebc Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Fri, 13 Jun 2025 16:52:03 -0500 Subject: [PATCH 6/7] style removing using directive for System.Runtime.CompilerServices --- .../Runtime/NetworkVariable/NetworkVariableBase.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs index c8dd1801f1..8761496d2a 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.CompilerServices; using UnityEngine; namespace Unity.Netcode From 365016d3927dc05980f0a8613a28fd03df457f80 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity Date: Fri, 13 Jun 2025 17:48:20 -0500 Subject: [PATCH 7/7] fix Missing encapsulated Boolean check. --- .../Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs index f02e2d6666..af520a0468 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs @@ -145,8 +145,8 @@ public void Serialize(FastBufferWriter writer, int targetVersion) var networkVariable = NetworkBehaviour.NetworkVariableFields[i]; var shouldWrite = networkVariable.IsDirty() && networkVariable.CanClientRead(TargetClientId) - && networkManager.IsServer || - (networkVariable.CanWrite && networkVariable.CanSend()); + && (networkManager.IsServer || + (networkVariable.CanWrite && networkVariable.CanSend())); // Prevent the server from writing to the client that owns a given NetworkVariable // Allowing the write would send an old value to the client and cause jitter