Skip to content

Commit 0d80039

Browse files
committed
perf(networked-vars): Skip NetworkList set operation when value unchanged
Added equality check in NetworkList indexer setter to avoid unnecessary operations when the new value equals the existing value. This improves performance by preventing redundant list events and network synchronization.
1 parent f4b6cd4 commit 0d80039

File tree

1 file changed

+7
-0
lines changed
  • com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections

1 file changed

+7
-0
lines changed

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@ public T this[int index]
617617
}
618618

619619
var previousValue = m_List[index];
620+
621+
// Compare the Value being applied to the current value
622+
if (NetworkVariableSerialization<T>.AreEqual(ref previousValue, ref value))
623+
{
624+
return;
625+
}
626+
620627
m_List[index] = value;
621628

622629
var listEvent = new NetworkListEvent<T>()

0 commit comments

Comments
 (0)