Skip to content

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

Open
NoelStephensUnity wants to merge 23 commits into
develop-2.0.0from
fix/spawn-disabled-in-scene-placed-and-network-prefab-registration
Open

fix: spawn disabled in scene placed and network prefab registration#4093
NoelStephensUnity wants to merge 23 commits into
develop-2.0.0from
fix/spawn-disabled-in-scene-placed-and-network-prefab-registration

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity 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 owner July 21, 2026 19:10
Fixing formatting issues.
Fixing some standards formatting related issues.
Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs Outdated
removing trailing spaces.
CreateServerAndClients(NumberOfClients);
}

internal virtual bool ShouldCreatePlayerPrefab()

Copy link
Copy Markdown
Member Author

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 thread com.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 thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
@codecov-github-com

codecov-github-com Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 68.04124% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 84.74% 9 Missing ⚠️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs 52.63% 9 Missing ⚠️
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs 0.00% 8 Missing ⚠️
....netcode.gameobjects/Runtime/Core/NetworkObject.cs 54.54% 5 Missing ⚠️
@@                Coverage Diff                @@
##           develop-2.0.0    #4093      +/-   ##
=================================================
+ Coverage          66.40%   67.00%   +0.59%     
=================================================
  Files                163      163              
  Lines              24999    25074      +75     
=================================================
+ Hits               16601    16800     +199     
+ Misses              8398     8274     -124     
Flag Coverage Δ
NGOv2_ubuntu_6000.3 67.00% <68.04%> (+0.59%) ⬆️

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

Files with missing lines Coverage Δ
....netcode.gameobjects/Runtime/Core/NetworkObject.cs 66.41% <54.54%> (+2.39%) ⬆️
...tcode.gameobjects/Editor/InScenePlacedProcessor.cs 40.62% <0.00%> (-13.55%) ⬇️
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 79.61% <84.74%> (+2.45%) ⬆️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs 67.24% <52.63%> (+0.79%) ⬆️

... and 5 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 67.00% <68.04%> (+0.59%) ⬆️

ℹ️ Need help interpreting these results?

Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Outdated
NoelStephensUnity and 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.
…egistration' of https://github.com/Unity-Technologies/com.unity.netcode.gameobjects into fix/spawn-disabled-in-scene-placed-and-network-prefab-registration
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.
@NoelStephensUnity
NoelStephensUnity enabled auto-merge (squash) July 24, 2026 18:53
Clarified the categories of NetworkObjects and their requirements. Added details for dynamically instantiated and in-scene placed NetworkObjects.
White spaces!
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.

2 participants