Skip to content

fix: Replaced HashSet.UnionWith() with loop in NetworkBehaviourUpdate() to avoid heap alloc #3568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down