Skip to content

fix: serialize the scene placed field and fix DA scene migration#4086

Merged
NoelStephensUnity merged 21 commits into
fix/in-scene-placed-edge-casesfrom
fix/set-in-scene-when-serializing
Jul 15, 2026
Merged

fix: serialize the scene placed field and fix DA scene migration#4086
NoelStephensUnity merged 21 commits into
fix/in-scene-placed-edge-casesfrom
fix/set-in-scene-when-serializing

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity commented Jul 14, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

This fixes an edge case scenario where non-spawned NetworkObjects migrated into the DDOL during awake would not get spawned upon starting a session as a server, host, or session owner.

While getting some of the validation tests for this working, ran into the issue with MTT-15430 which required fixing that issue in order to get some of the newer and adjusted tests to work. So, this PR includes the fix for this too.

Jira ticket

Extension fixes for #4073
Also fixes MTT-15430

Changelog

  • Fixed: Issue where scene migration in a distributed authority session would throw an exception on clients migrating their owned NetworkObject instances to a different scene.

  • Fixed: Issue where migrating a dynamically spawned or in-scene placed NetworkObject into a different scene during awake could result in that spawned instance to not be synchronized.

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
    • Added NetworkSceneManagerStartupTests and associated assets to testproject.

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.

Backports

Does not require a backport.

- Adjusted the `InScenePlaced` property to internally set or publicly get the serialized `m_InScenePlaced` field.
- `NetworkObject` now implements `ISerializationCallbackReceiver` to assure `m_InScenePlaced` is always properly set for in-scene placed objects.
- Removed legacy define for UNITY_2021_2_OR_NEWER since v2.x.x+ is only for Unity v6.
- Adding `NetworkSceneManagerStartupTests` which validates this PR.
- Adding the assets and script needed to validate this PR.
- Updated scenes in build list to include the new scene: InSceneNetworkObjectMovesToDDOL.
Adding change log entry.
@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review July 14, 2026 17:03
@NoelStephensUnity
NoelStephensUnity requested a review from a team as a code owner July 14, 2026 17:03
@codecov-github-com

codecov-github-com Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 41.62437% with 115 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
....netcode.gameobjects/Runtime/Core/NetworkObject.cs 40.47% 25 Missing ⚠️
...eobjects/Runtime/SceneManagement/SceneEventData.cs 0.00% 20 Missing ⚠️
...cts/Runtime/SceneManagement/NetworkSceneManager.cs 0.00% 18 Missing ⚠️
...gameobjects/Runtime/Configuration/NetworkPrefab.cs 14.28% 12 Missing ⚠️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs 45.00% 11 Missing ⚠️
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs 20.00% 8 Missing ⚠️
...time/SceneManagement/DefaultSceneManagerHandler.cs 0.00% 5 Missing ⚠️
...netcode.gameobjects/Editor/NetworkManagerHelper.cs 0.00% 4 Missing ⚠️
...gameobjects/Runtime/Components/NetworkTransform.cs 77.77% 4 Missing ⚠️
...cts/Runtime/Connection/NetworkConnectionManager.cs 55.55% 4 Missing ⚠️
... and 1 more
@@                Coverage Diff                @@
##           develop-2.0.0    #4086      +/-   ##
=================================================
+ Coverage          66.30%   66.41%   +0.10%     
=================================================
  Files                163      163              
  Lines              24927    24999      +72     
=================================================
+ Hits               16528    16603      +75     
+ Misses              8399     8396       -3     
Flag Coverage Δ
NGOv2_ubuntu_6000.3 66.41% <41.62%> (+0.10%) ⬆️

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

Files with missing lines Coverage Δ
...ponents/Interpolator/BufferedLinearInterpolator.cs 86.31% <100.00%> (ø)
...meobjects/Runtime/Spawning/NetworkPrefabHandler.cs 61.26% <100.00%> (ø)
...netcode.gameobjects/Editor/NetworkManagerHelper.cs 48.36% <0.00%> (ø)
...gameobjects/Runtime/Components/NetworkTransform.cs 81.21% <77.77%> (ø)
...cts/Runtime/Connection/NetworkConnectionManager.cs 80.62% <55.55%> (ø)
....netcode.gameobjects/Runtime/Logging/NetworkLog.cs 73.01% <82.60%> (+19.01%) ⬆️
...time/SceneManagement/DefaultSceneManagerHandler.cs 20.86% <0.00%> (ø)
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs 54.16% <20.00%> (-24.41%) ⬇️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs 66.44% <45.00%> (+0.29%) ⬆️
...gameobjects/Runtime/Configuration/NetworkPrefab.cs 66.35% <14.28%> (-7.84%) ⬇️
... and 3 more

... and 4 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 66.41% <41.62%> (+0.10%) ⬆️

ℹ️ Need help interpreting these results?

Fixing issue with marking things as in-scene placed during runtime.
Commenting out the addressable scene test.
Adding back the check for InScenePlaced when shutting down.
- `ISerializationCallbackReceiver` implementation as that does not accomplish what we need.
- Setting InScenePlaced within OnValidate instead.
Only reset things that have been spawned are in-scene placed, and is assigned to the relative NetworkManager (for integration testing purposes)
Removing the addressable scene.
We will revisit this when this is supported.
Fixing several issues with NetworkObjectSceneMigrationTests.
Fixing several formatting issues.
brackets adjustment.
Adding white spaces between foreach and if
Fixing some out of alignment if statements.
Didn't save the change... adding last standards check issue fix.
Fixing issue where we were sending scene migration notifications when migrating into the DDOL.
Fixing issue where if a client detected a changed scene but had no scene change to send (later) it would throw and exception and cause a memory leak.
Remove the legacy multiprocess scene that is no longer used and has references to scripts that no longer exist.
Issue where distributed authority would throw an exception during scene migration due to the fact that we would throw an exception if the 1st scene in the scene migration table didn't contain the client that has authority over the NetworkObject that migrated into a new scene. Now we count how many entries were written and if that count is zero upon parsing known loaded scenes then it throws an exception.

Reverting the exclusion of DDOL synchronization (that was a red herring).
Removing the ValidateSceneOnAllClients portion as that doesn't assure that all clients have loaded the scene and fully synchronized the scene which could lead to edge case issues during this test.
@NoelStephensUnity
NoelStephensUnity changed the base branch from develop-2.0.0 to fix/in-scene-placed-edge-cases July 15, 2026 22:54
Adding and updating the change log entries for this PR.
@NoelStephensUnity NoelStephensUnity changed the title fix: set the in scene placed field prior to serializing fix: serialize the scene placed field and fix DA scene migration Jul 15, 2026
@NoelStephensUnity
NoelStephensUnity merged commit bebbc3a into fix/in-scene-placed-edge-cases Jul 15, 2026
6 checks passed
@NoelStephensUnity
NoelStephensUnity deleted the fix/set-in-scene-when-serializing branch July 15, 2026 23:00
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