Skip to content

fix: invoke OnNetCodeDisconnect when a hybrid connection closes - #4209

Merged
EmandM merged 11 commits into
develop-3.x.xfrom
fix/hybrid-disconnect-events
Oct 27, 2026
Merged

EmandM merged 11 commits into
develop-3.x.xfrom
fix/hybrid-disconnect-events

Conversation

@NoelStephensUnity

Copy link
Copy Markdown
Member

Purpose of this PR

In a hybrid mode session, NetworkManager.OnNetCodeDisconnect was only invoked when the session shut down, not when a connection closed.

When N4E destroys a connection entity, only its cleanup components remain. UnifiedUpdateConnections queried for NetworkId together with ConnectionState, so it never matched a closed connection. The NetworkId is now stored in ConnectionState when the connection goes in game and read from there on disconnect.

Jira ticket

N/A

Changelog

  • Fixed: Issue where NetworkManager.OnNetCodeDisconnect was not invoked when a connection closed during a hybrid mode session, only when the session shut down.

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Automated tests:

  • Covered by new automated tests

HybridConnectionEventsTests (UnifiedHost and UnifiedServer) checks the connect event fires once the client is synchronized and the server reports a client disconnect while the session is still running.

Up-port

Not needed; hybrid mode is NGO 3.x only.

Backports

Not needed.

A destroyed connection entity keeps only its cleanup components, so the
query requiring NetworkId alongside ConnectionState never matched and the
disconnect was only reported at shutdown. Read the id from ConnectionState
instead, and set it when the connection goes in game.
@NoelStephensUnity
NoelStephensUnity requested a review from a team as a code owner October 22, 2026 16:51

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Ship it

The change caches connection IDs for disconnect reporting after entity cleanup and adds hybrid host/server regression coverage. I examined connection updates, shutdown handling, event subscribers, test lifecycle, and release notes, and found no actionable issues.

Reviewed commit 4a84c3e

🤖 Helpful? 👍/👎

@NoelStephensUnity
NoelStephensUnity marked this pull request as draft October 22, 2026 17:01
@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review October 22, 2026 17:01

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Ship it

The change preserves the connection ID for disconnect callbacks after entity destruction. I examined the cleanup flow, transport shutdown behavior, and hybrid test setup; I found no actionable issues.

Reviewed commit 4a84c3e

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 50.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...netcode.gameobjects/Runtime/Core/NetworkManager.cs 0.00% 4 Missing ⚠️
...ime/Components/Helpers/UnifiedUpdateConnections.cs 0.00% 2 Missing ⚠️
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 0.00% 1 Missing ⚠️
@@                Coverage Diff                @@
##           develop-3.x.x    #4209      +/-   ##
=================================================
+ Coverage          75.93%   76.25%   +0.32%     
=================================================
  Files                159      159              
  Lines              27405    27538     +133     
=================================================
+ Hits               20809    21000     +191     
+ Misses              6596     6538      -58     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 75.32% <50.00%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...cts/Runtime/Configuration/HybridNetcodeDefaults.cs 100.00% <100.00%> (ø)
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 76.89% <0.00%> (ø)
...ime/Components/Helpers/UnifiedUpdateConnections.cs 0.00% <0.00%> (ø)
...netcode.gameobjects/Runtime/Core/NetworkManager.cs 71.81% <0.00%> (-0.30%) ⬇️

... and 3 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 76.25% <40.84%> (+0.32%) ⬆️

ℹ️ Need help interpreting these results?

@EmandM
EmandM enabled auto-merge (squash) October 26, 2026 21:29
@NoelStephensUnity
NoelStephensUnity marked this pull request as draft October 27, 2026 15:04
auto-merge was automatically disabled October 27, 2026 15:04

Pull request was converted to draft

@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review October 27, 2026 15:04

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Harness Review

Ship it

The change preserves connection IDs for hybrid disconnect notifications and allows empty prefab rejection messages. I examined the connection lifecycle, prefab registration guards, and new tests against their setup and teardown behavior, and found no actionable issues.

Reviewed commit 1dcf26e

🤖 Helpful? 👍/👎

@EmandM
EmandM enabled auto-merge (squash) October 27, 2026 15:07
netcode-ci-service and others added 3 commits October 27, 2026 15:56
Netcode for Entities now puts connections in game automatically by default
(NetcodeConfig.AutomaticStateReplication), which stops UnifiedUpdateConnections
from seeing new connections: no connect events, no in-session disconnects, and
ghosts stream to a client before NGO has synchronized it. Disable it at runtime
alongside the other hybrid NetcodeConfig settings.
@EmandM
EmandM merged commit 212a491 into develop-3.x.x Oct 27, 2026
26 of 27 checks passed
@EmandM
EmandM deleted the fix/hybrid-disconnect-events branch October 27, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants