Skip to content

fix: spawn disabled in scene placed and network prefab registration - #4093

Merged
NoelStephensUnity merged 25 commits into
develop-2.0.0from
fix/spawn-disabled-in-scene-placed-and-network-prefab-registration
Jul 28, 2026
Merged

fix: spawn disabled in scene placed and network prefab registration#4093
NoelStephensUnity merged 25 commits into
develop-2.0.0from
fix/spawn-disabled-in-scene-placed-and-network-prefab-registration

Conversation

@NoelStephensUnity

@NoelStephensUnityNoelStephensUnity commented Jul 21, 2026

Copy link
Copy Markdown
Member

Purpose of this PR

This is a continuation of the fixes for the initial spawn sequence on the session owner/server side.
This PR includes:

  • A fix for not being able to spawn an in-scene placed NetworkObject if it is initially disabled in the scene.
  • A fix for not allowing users to spawn dynamically generated NetworkObjects during runtime where the NetworkObject.GlobalObjectIdHash is zero.
  • Some potential edge case exceptions.
  • Overhauled several integration tests that were not properly creating network prefabs.

Jira ticket

NA

Changelog

  • Fixed: issue with not being able to spawn initially disabled in-scene placed objects.
  • Fixed: issue with pre-instantiated network prefab instances being marked as in-scene placed. Now pre-instantiated network prefabs are dynamically spawned.
  • Fixed: issue where a user could spawn runtime created NetworkObject that has a GlobalObjectIdHash of zero. These are not valid instances and will no longer be allowed to spawn.

Documentation

  • Documentation changes are necessary.
    • In-scene placed NetworkObjects section was updated to include pre-disabled in-scene placed NetworkObjects.
    • NetworkObject section was updated to provide a high-level overview of what is and is not a valid NetworkObject.

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

Functional Testing

Manual testing :

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 is required.

Backports

No back port is required.

- Issue where disabled in-scene placed NetworkObjects could not be spawned after starting a session.
- Issue where users are allowed to spawn a NetworkObject with a GlobalObjectIdHash value of 0 (zero).
NetworkAnimator not pointing to an animator within awake now just logs a warning as opposed to an error.
Updating tests based on the fixes applied to this branch.
A large portion is related to some integration tests trying to spawn NetworkObjects with a GlobalObjectIdHash value of zero(0).
Style and providing internal write access to the prefabs list.
Potentially last iteration on fixing/updating integration tests.
Using the fixed version of NetworkPrefabHandlerSpawnAndSynchronizeTests.
Fixing some issues with prefab and handler creation.
@NoelStephensUnity
NoelStephensUnity marked this pull request as ready for review July 21, 2026 19:10
@NoelStephensUnity
NoelStephensUnity requested a review from a team as a code ownerJuly 21, 2026 19:10
Fixing formatting issues.
Fixing some standards formatting related issues.
Comment threadcom.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs Outdated
removing trailing spaces.
CreateServerAndClients(NumberOfClients);
}

internal virtual bool ShouldCreatePlayerPrefab()

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We might make this protected, but it seemed we needed a way to more easily control whether we should spawn the player prefab or not.

Comment threadcom.unity.netcode.gameobjects/Tests/Runtime/NetworkManagerPlayerPrefab.cs Outdated
Super weird one... but using ? as opposed to an if null check.
Removing commented out code that is no longer needed/used.
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
@codecov-github-com

codecov-github-comBot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 75.25773% with 24 lines in your changes missing coverage. Please review.

Files with missing linesPatch %Lines
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs84.74%9 Missing ⚠️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs68.42%6 Missing ⚠️
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs37.50%5 Missing ⚠️
....netcode.gameobjects/Runtime/Core/NetworkObject.cs63.63%4 Missing ⚠️
@@ Coverage Diff @@## develop-2.0.0 #4093 +/- ##
=================================================
- Coverage 73.87% 73.83% -0.04% 
=================================================
Files 172 172 Lines 28013 28094 +81 =================================================
+ Hits 20695 20744 +49 - Misses 7318 7350 +32 
FlagCoverage Δ
NGOv2_project_testproject_ubuntu_pinnedTrunk73.62% <75.25%> (?)
NGOv2_project_testproject_ubuntu_trunk?

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

Files with missing linesCoverage Δ
....gameobjects/Runtime/Components/NetworkAnimator.cs76.02% <ø> (ø)
....netcode.gameobjects/Runtime/Core/NetworkObject.cs75.34% <63.63%> (+0.45%)⬆️
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs75.00% <37.50%> (-12.50%)⬇️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs73.18% <68.42%> (-0.11%)⬇️
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs81.55% <84.74%> (+1.92%)⬆️

... and 4 files with indirect coverage changes

ComponentsCoverage Δ
com.unity.netcode.gameobjects73.83% <77.35%> (-0.04%)⬇️

ℹ️ Need help interpreting these results?

Comment threadcom.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment threadcom.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
NoelStephensUnityand others added 6 commits July 24, 2026 09:46
Committing suggested changes.
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
Applying changes based on review discussion.
Making adjustments based on review discussion.
Removing field that is no longer valid.
Moving Awake higher in NetworkObject as it has become wedged in the middle of the code.
Adding change log entries.
Inverting logic (oops)
Updating NetworkObject documentation and in-scene placed documentation.
Clarified the categories of NetworkObjects and their requirements. Added details for dynamically instantiated and in-scene placed NetworkObjects.
White spaces!
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
@NoelStephensUnity
NoelStephensUnity enabled auto-merge (squash) July 28, 2026 14:35
@NoelStephensUnity
NoelStephensUnity merged commit 9b620fb into develop-2.0.0Jul 28, 2026
26 checks passed
@NoelStephensUnity
NoelStephensUnity deleted the fix/spawn-disabled-in-scene-placed-and-network-prefab-registration branch July 28, 2026 23:13
michalChrobot added a commit that referenced this pull request Aug 3, 2026
* chore: Adding a note about DontDestroyOnLoad usage for Networked scene objects (#4070)
Docs correction
* ci: Split code coverage into Package Test and Project Test jobs (#4101)
* ci: Split code coverage into Package Test and Project Test jobs
Convert the existing coverage job to [Code Coverage] Package Test - NGO [ubuntu, trunk] and add [Code Coverage] Project Test - NGO testproject [ubuntu, trunk]. Wire Package Test into PR/nightly triggers and Project Test into the weekly run.
* ci: Run both coverage jobs on PR and nightly
* ci: Use pinnedTrunk for PR coverage and drop package-test job
* chore: Point CMB resources at new monorepo (#4106)
* chore: Point CMB resources at new monorepo
* fix: NetworkVariable change prior to ownership change using distributed authority topology fails to sync NetworkVariable (#4107)
* fix
This resolves the issue where in a distributed authority session changing a NetworkVariable prior to changing ownership in the same call-stack would result in the NetworkVariable not being synchronized.
* fix - update
Removing the additional authority check as it is not needed.
Fixing a very edge case scenario that shouldn't happen but in the event it does when finding objects by type within a specific scene, if the scene is invalid then use an empty array for the found objects.
* fix: spawn disabled in scene placed and network prefab registration (#4093)
* fix
- Issue where disabled in-scene placed NetworkObjects could not be spawned after starting a session.
- Issue where users are allowed to spawn a NetworkObject with a GlobalObjectIdHash value of 0 (zero).
* update
NetworkAnimator not pointing to an animator within awake now just logs a warning as opposed to an error.
* test
Updating tests based on the fixes applied to this branch.
A large portion is related to some integration tests trying to spawn NetworkObjects with a GlobalObjectIdHash value of zero(0).
* update
Style and providing internal write access to the prefabs list.
* test
Potentially last iteration on fixing/updating integration tests.
* test - fix
Using the fixed version of NetworkPrefabHandlerSpawnAndSynchronizeTests.
Fixing some issues with prefab and handler creation.
* style
Fixing formatting issues.
* style
Fixing some standards formatting related issues.
* style
removing trailing spaces.
* style
Super weird one... but using ? as opposed to an if null check.
* style
Removing commented out code that is no longer needed/used.
* update
Committing suggested changes.
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
* update
Applying changes based on review discussion.
* update
Making adjustments based on review discussion.
* style
Removing field that is no longer valid.
Moving Awake higher in NetworkObject as it has become wedged in the middle of the code.
* update
Adding change log entries.
* update
Inverting logic (oops)
* doc
Updating NetworkObject documentation and in-scene placed documentation.
* Update documentation for the two types of NetworkObjects
Clarified the categories of NetworkObjects and their requirements. Added details for dynamically instantiated and in-scene placed NetworkObjects.
* style
White spaces!
* Apply suggestions from code review
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
---------
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
* docs: Docs-wide link fixes and xref update (#4102)
* Docs-wide link fixes and xref update
* Typo in API docs
* chore: Add NGO_EXCLUDE_HEAVY_TESTS define (#4114)
Add NGO_EXCLUDE_HEAVY_TESTS
---------
Co-authored-by: Nikos <nikos@unity3d.com>
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
Co-authored-by: Noel Stephens <noel.stephens@unity3d.com>
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
Co-authored-by: mnachury-unity <120488254+mnachury-unity@users.noreply.github.com>
Sign up for freeto 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

@NoelStephensUnity@EmandM@jabbacakes