From 97737be22b5d818f82b1b578657e1cee0796053d Mon Sep 17 00:00:00 2001 From: Louis McLaughlin Date: Thu, 24 Jul 2025 11:08:37 +0800 Subject: [PATCH 1/3] Replaced HashSet.UnionWith() with loop to avoid heap alloc --- .../Runtime/Core/NetworkBehaviourUpdater.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs index 105f203c86..4b9341b327 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs @@ -34,7 +34,10 @@ internal void NetworkBehaviourUpdate(bool forceSend = false) #endif try { - m_DirtyNetworkObjects.UnionWith(m_PendingDirtyNetworkObjects); + foreach (var o in m_PendingDirtyNetworkObjects) + { + m_DirtyNetworkObjects.Add(o); + } m_PendingDirtyNetworkObjects.Clear(); // NetworkObject references can become null, when hidden or despawned. Once NUll, there is no point From ff6c92b9e0e4bb5da7b39f803ca0a03b6f9e6464 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 1 Aug 2025 14:31:48 -0400 Subject: [PATCH 2/3] Update CHANGELOG --- com.unity.netcode.gameobjects/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/CHANGELOG.md b/com.unity.netcode.gameobjects/CHANGELOG.md index 489af4f446..a5deadf23d 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -17,6 +17,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Removed allocation to the heap in NetworkBehaviourUpdate. (#3573) - Fixed issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. (#3564) - Fixed regression issue in v2.x where `NetworkObject.GetNetworkBehaviourAtOrderIndex` was converted from public to internal. (#3541) - Fixed ensuring OnValueChanged callback is still triggered on the authority when a collection changes and then reverts to the previous value in the same frame. (#3539) From 174117fcea82811eeb72c383581c51c5b65c53a7 Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Tue, 5 Aug 2025 14:40:29 -0500 Subject: [PATCH 3/3] Update NetworkBehaviourUpdater.cs just minor style fix --- .../Runtime/Core/NetworkBehaviourUpdater.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs index 4b9341b327..943257dd74 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviourUpdater.cs @@ -34,9 +34,9 @@ internal void NetworkBehaviourUpdate(bool forceSend = false) #endif try { - foreach (var o in m_PendingDirtyNetworkObjects) + foreach (var dirtyNetworkObject in m_PendingDirtyNetworkObjects) { - m_DirtyNetworkObjects.Add(o); + m_DirtyNetworkObjects.Add(dirtyNetworkObject); } m_PendingDirtyNetworkObjects.Clear();