From eac30d4664916eb4b1d9a51e972a4b2ec7360317 Mon Sep 17 00:00:00 2001 From: Louis McLaughlin Date: Thu, 24 Jul 2025 11:08:37 +0800 Subject: [PATCH 1/2] 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 524f6a2025..beb540891b 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 33144938e068141c601c3b016e67b36ca56b6d11 Mon Sep 17 00:00:00 2001 From: Emma Date: Fri, 1 Aug 2025 11:17:45 -0400 Subject: [PATCH 2/2] 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 7fdab72391..ea57b68a2a 100644 --- a/com.unity.netcode.gameobjects/CHANGELOG.md +++ b/com.unity.netcode.gameobjects/CHANGELOG.md @@ -14,6 +14,7 @@ Additional documentation and release notes are available at [Multiplayer Documen ### Fixed +- Removed allocation to the heap in NetworkBehaviourUpdate. (#3568) - Fixed issue where NetworkConfig.ConnectionData could cause the ConnectionRequestMessage to exceed the transport's MTU size and would result in a buffer overflow error. (#3565) ### Changed