Skip to content

fix: server not tracking scene handles for pre-loaded scenes - #4145

Open
NoelStephensUnity wants to merge 3 commits into
develop-2.0.0from
fix/server-not-tracking-scene-handles-for-pre-loaded-scenes
Open

fix: server not tracking scene handles for pre-loaded scenes#4145
NoelStephensUnity wants to merge 3 commits into
develop-2.0.0from
fix/server-not-tracking-scene-handles-for-pre-loaded-scenes

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity commented Aug 26, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

Scenes that were already loaded when a session starts were added to ScenesLoaded but never to the server-to-client scene handle tables, so UnloadScene passed its ScenesLoaded check and then failed inside RemoveServerClientSceneHandle. The scene unloaded on every peer, but an error was logged and the ScenesLoaded entry was never removed.

The client-server branch of the NetworkSceneManager constructor now registers those scenes the same way InitializeScenesLoaded does for distributed authority.

NetcodeIntegrationTestHelpers registered the test runner scene in ServerSceneHandleToClientSceneHandle unconditionally, which now collides with the constructor already having added it, so that add is guarded.

fix: #4140

Jira ticket

(Needs ticket)

Changelog

  • Fixed: Issue where scenes additively loaded before a session started were tracked as loaded on the server but had no scene handle entries, which caused NetworkSceneManager.UnloadScene to log an error and leave the scene registered as loaded even though it unloaded on all peers.

Documentation

  • No documentation changes or additions were necessary.

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

Functional Testing

Manual testing :

  • Manual testing done

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does the change require QA team to:

  • Review automated tests?
  • Execute manual tests?
  • Provide feedback about the PR?

If any boxes above are checked the QA team will be automatically added as a PR reviewer.

Up-port

Up-port: #4146
Requires up-port.

Backports

No backport required.

Scenes that were already loaded when a session starts were added to
ScenesLoaded but never to the server-to-client scene handle tables, so
UnloadScene passed its ScenesLoaded check and then failed inside
RemoveServerClientSceneHandle. The scene unloaded on every peer, but an
error was logged and the ScenesLoaded entry was never removed.

The client-server branch of the NetworkSceneManager constructor now
registers those scenes the same way InitializeScenesLoaded does for
distributed authority.

NetcodeIntegrationTestHelpers registered the test runner scene in
ServerSceneHandleToClientSceneHandle unconditionally, which now collides
with the constructor already having added it, so that add is guarded.

@u-pr u-pr Bot left a comment

Copy link
Copy Markdown

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 preload initialization now establishes the complete bidirectional handle state required by the existing unload lifecycle, while the test helper avoids re-registering the runner scene. I examined the constructor guard, mapping add/remove semantics, client synchronization paths, and the added regression test; no actionable defects were identified.

Reviewed commit fe16590

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@                Coverage Diff                @@
##           develop-2.0.0    #4145      +/-   ##
=================================================
+ Coverage          73.88%   73.95%   +0.07%     
=================================================
  Files                172      172              
  Lines              28105    28105              
=================================================
+ Hits               20765    20785      +20     
+ Misses              7340     7320      -20     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu_pinnedTrunk 73.67% <100.00%> (?)

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

Files with missing lines Coverage Δ
...cts/Runtime/SceneManagement/NetworkSceneManager.cs 79.49% <100.00%> (ø)

... and 1 file with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 73.95% <100.00%> (+0.07%) ⬆️

ℹ️ Need help interpreting these results?

@NoelStephensUnity
NoelStephensUnity enabled auto-merge (squash) August 27, 2026 15:22

@EmandM EmandM left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Just one tiny comment

…eIntegrationTestHelpers.cs

Co-authored-by: Emma <emma.mcmillan@unity3d.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnloadScene always errors on scenes loaded before the server started

2 participants