Skip to content

fix: [Backport] Ensure all loaded scenes are registered on session owner promotion - #4217

Open
EmandM wants to merge 2 commits into
develop-2.0.0from
backport/fix/scene-validation-after-host-migration
Open

EmandM wants to merge 2 commits into
develop-2.0.0from
backport/fix/scene-validation-after-host-migration

Conversation

@EmandM

@EmandM EmandM commented Oct 26, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

Backport of #4214

Currently, when a client starts the session as a DA session owner their NetworkSceneManger initializes all the existing loaded scenes so they can correctly synchronize incoming clients.

This PR ensures that clients promoted to session owner mid-session also initialize their existing loading scenes.

This fixes an error where an active scene that was loaded before the game started would break synchronization on late-joining clients after a new session owner was promoted.

Jira ticket

UUM-154485

Changelog

  • Fixed: Issue where a client promoted to session owner could throw an exception when synchronizing a newly joining client.

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

This is a backport of #4214

Backports

n/a

@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

Needs changes

The change is focused on session-owner promotion and active-scene synchronization, but the migration handling needs another pass.

Reviewed commit 4cb6c5a

🤖 Helpful? 👍/👎


if (isSessionOwner && NetworkConfig.EnableSceneManagement)
{
SceneManager.InitializeScenesLoaded();

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.

P1

Late joining can still fail on a promoted CMB owner when a locally loaded additive scene's handle collides with an existing shared handle. With ServerSceneHandleToClientSceneHandle[100] = 200, another local scene can have handle 100, because Unity scene handles are client-local. InitializeScenesLoaded passes 100 as both handles, so UpdateServerClientSceneHandle returns before adding the missing reverse mapping. AddSceneToClientSynchronization then indexes that missing entry and throws KeyNotFoundException. Reuse existing client-to-server mappings during initialization. Assign an unused shared handle when registering a new scene.

🤖 Helpful? 👍/👎

AssertOnTimeout("Session owner promotion failed!");

// Connect a late-joining client to verify the new session owner handles the previously unregistered scene.
yield return CreateAndStartNewClient();

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.

P2

This regression test can pass even if the promoted owner never registers EmptyScene. AddActiveSceneToClientSynchronization now warns and omits an unregistered active scene instead of throwing. The test managers share Unity's scene hierarchy, so EmptyScene is already loaded and active for the late joiner. CreateAndStartNewClient checks connection and player clones, which can complete without synchronizing that scene. Assert that the promoted owner registers EmptyScene. Assert that the late joiner receives the scene's shared-handle mapping.

🤖 Helpful? 👍/👎

This branch has not been deployed

No deployments
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.

1 participant