Skip to content

chore: enable unified netcode from N4E 7.2.0, only for hybrid prefab sessions - #4186

Open
NoelStephensUnity wants to merge 10 commits into
develop-3.x.xfrom
chore/remove-n4e-experimental-define
Open

NoelStephensUnity wants to merge 10 commits into
develop-3.x.xfrom
chore/remove-n4e-experimental-define

Conversation

@NoelStephensUnity

@NoelStephensUnity NoelStephensUnity commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Purpose of this PR

The unified path no longer needs any scripting define: it compiles in when the project resolves Netcode for Entities 7.2.0 or later, and only runs when a session has hybrid prefabs.

N4E 7.2.0 is the GA release of its GameObject layer and drops NETCODE_GAMEOBJECT_BRIDGE_EXPERIMENTAL (unity/unity PR 130027). This PR adapts NGO to it.

PR Scope:

  • UNIFIED_NETCODE is an asmdef versionDefine on com.unity.netcode 7.2.0 in the Runtime, Editor, Runtime.Tests and TestProject.Runtime.Tests assemblies. Released N4E 7.0.0 and 7.1.0 keep it off.

  • OUT_OF_BAND_RPC, the bridge-define #error and UNIFIED_NETCODE_7_0_0 are removed (every N4E NGO 3.x supports uses the new namespace).

  • Hybrid mode only for sessions with hybrid prefabs: UnifiedBootstrap is no longer picked by Entities as the startup bootstrap for every project. NetworkManager creates it only when a hybrid prefab is registered before the session starts, from a NetworkPrefabsList or AddNetworkPrefab. A hybrid prefab added after a session started without one now logs an error and is not registered; before, it switched the session into hybrid mode and stopped its send queue. A hybrid PlayerPrefab outside the prefab lists now counts toward that decision too; before, it was registered after the transport was chosen.

  • testproject takes N4E from unity/unity by git, since 7.2.0 is not published yet. manifest-unified.json is deleted, and the unified job no longer edits the manifest or ProjectSettings.

  • The NetcodeConfig assets are no longer tracked in testproject and minimalproject, nor their NetCodeClientAndServerSettings.asset. NGO applies the values it needs at session start, and Netcode for Entities creates both files on first open (a tracked settings file would be rewritten on every fresh checkout), and both projects' .gitignore now exclude them so they are not committed back.

Out of scope:

  • NGO's package.json stays on com.unity.netcode 7.1.0 (7.2.0 is unpublished, and depending on it fails package validation). It moves to 7.2.0 once N4E publishes.
  • RpcTestsAutomated(UnifiedHost) throws ObjectDisposedException in OneTimeTearDown when it runs in the full unified suite (pre-existing on develop-3.x.x).

Before merge: unity/unity PR 130027 merges first, then testproject/Packages/manifest.json goes from #netcode/remove-exp-define-ghost-object back to #trunk.

Jira ticket:

None

Documentation

  • No documentation changes or additions were necessary.

Testing & QA

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests: UnifiedHybridPrefabValidationTests.HybridPrefabAddedAfterStartIsRejected and HybridPlayerPrefabCountsBeforeStart.
Run (6000.7.0b3) N4E Passed Failed
Unified playmode suite, UNIFIED_TESTS=true, no scripting defines, after merging develop-3.x.x (#4176, #4144) PR 130027 branch (7.2.0) 293 0 (1 intermittent PeerDisconnectCallbackTests case; 36/36 on rerun)
NetworkVariableTests, non-unified job, with UNIFIED_NETCODE compiled in PR 130027 branch (7.2.0) 886 0
HybridNetcodeDefaultsTests (EditMode) PR 130027 branch (7.2.0) 7 0
Standalone build + run, Windows (replicating the desktop standalone job), testproject without the NetcodeConfig asset PR 130027 branch (7.2.0) 6254 0
Unified validation, prefab handler and RPC tests registry 7.1.0 (unified compiled out) 4 0

Up-port

Not needed: unified work is develop-3.x.x only.

Backports

Not needed.

N4E is removing NETCODE_GAMEOBJECT_BRIDGE_EXPERIMENTAL and making its GameObject layer public,
so UNIFIED_NETCODE is now the only define the unified path needs. testproject takes N4E from
unity/unity trunk until that change ships in a package, which makes manifest-unified.json redundant.
…sions

UNIFIED_NETCODE is now an asmdef versionDefine on com.unity.netcode 7.2.0, the release that makes the
GameObject layer public, so no project define is needed. UNIFIED_NETCODE_7_0_0 is gone since every
supported N4E uses the new namespace.

UnifiedBootstrap is marked DisableBootstrapOverrides and created by NetworkManager only when the session
has hybrid prefabs, so projects without them keep N4E's own startup bootstrap. A hybrid prefab added
after a session started without one is rejected.

testproject takes N4E from the remove-experimental-define branch until that PR merges.
@NoelStephensUnity
NoelStephensUnity requested review from a team and EmandM as code owners October 7, 2026 20:20
@u-pr

u-pr Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

⚠️ Some settings were ignored in '.pr_agent.toml (repository root)' repo settings

Check the configuration's TOML syntax, permitted settings, and size limit. See the error below.


Error message:
Ignored prohibited settings: github_app.handle_pr_actions. Permitted settings were applied.

Configuration content:
# This is the configuration for the u-pr bot
# https://github.cds.internal.unity3d.com/unity/u-pr
# For configuration of this file:
# https://developer.portal.internal.unity.com/catalog/default/component/u-pr/docs/configuration/automatic_runs/

[github_app]
handle_pr_actions = ['opened', 'ready_for_review']  # PR events that auto-run pr_commands
pr_commands       = ["/harness-review"]             # what runs on those events
reviewer_commands = ["/harness-review"]             # what runs when @u-pr is added as reviewer

@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 version-gated unified path has concrete regressions in session startup, world cleanup, and test-project dependency resolution.

P1

Stopping an NGO hybrid session also destroys unrelated Entities worlds when N4E's startup bootstrap has created them. [DisableBootstrapOverrides] now lets N4E's bootstrap run before NGO creates its hybrid world. ShutdownInternal still calls World.DisposeAllWorlds() whenever HasGhostPrefabs is true. That call disposes every Entities world, including ones outside NetworkManager.NetcodeWorld. Track the worlds created for the NGO session. Dispose only those worlds during NGO shutdown.

Reviewed commit e107a83

🤖 Helpful? 👍/👎

Comment thread testproject/Packages/manifest.json
A hybrid PlayerPrefab outside the prefab lists was registered after the transport choice and the
session-start rejection, so it was rejected. It now registers with the prefab lists before start, and
distributed authority rejects it like any other hybrid prefab.
…in testproject

UNIFIED_NETCODE is now defined automatically from N4E 7.2.0, so the Standards check formats code behind it
for the first time.
…-n4e-experimental-define

# Conflicts:
#	com.unity.netcode.gameobjects/Runtime/Components/Helpers/NetworkObjectBridge.cs
Keeps an implicit bool check where null propagation would call into a destroyed NetworkBehaviour.
@codecov-github-com

codecov-github-com Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 44.82759% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
....gameobjects/Runtime/Spawning/GhostSpawnManager.cs 0.00% 5 Missing ⚠️
...ameobjects/Runtime/Spawning/NetworkSpawnManager.cs 72.72% 3 Missing ⚠️
...time/Transports/Unified/UnifiedNetcodeTransport.cs 0.00% 3 Missing ⚠️
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 50.00% 2 Missing ⚠️
...netcode.gameobjects/Runtime/Core/NetworkManager.cs 33.33% 2 Missing ⚠️
...objects/Runtime/Components/NetworkRigidBodyBase.cs 0.00% 1 Missing ⚠️
@@                Coverage Diff                @@
##           develop-3.x.x    #4186      +/-   ##
=================================================
- Coverage          78.26%   76.14%   -2.13%     
=================================================
  Files                153      159       +6     
  Lines              26359    27333     +974     
=================================================
+ Hits               20631    20812     +181     
- Misses              5728     6521     +793     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 75.20% <44.82%> (-2.10%) ⬇️

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

Files with missing lines Coverage Δ
.../Runtime/Components/Helpers/NetworkObjectBridge.cs 0.00% <ø> (ø)
...cts/Runtime/Components/Helpers/UnifiedBootstrap.cs 0.00% <ø> (ø)
...ime/Components/Helpers/UnifiedUpdateConnections.cs 28.98% <ø> (ø)
...cts/Runtime/Configuration/HybridNetcodeDefaults.cs 100.00% <ø> (ø)
...gameobjects/Runtime/Configuration/NetworkConfig.cs 64.62% <100.00%> (+1.50%) ⬆️
....netcode.gameobjects/Runtime/Core/NetworkObject.cs 73.82% <ø> (-1.49%) ⬇️
...cts/Runtime/NetworkVariable/NetworkVariableBase.cs 87.50% <100.00%> (+0.32%) ⬆️
...meobjects/Runtime/Spawning/NetworkPrefabHandler.cs 66.66% <ø> (ø)
...objects/Runtime/Components/NetworkRigidBodyBase.cs 41.26% <0.00%> (-0.10%) ⬇️
...ameobjects/Runtime/Configuration/NetworkPrefabs.cs 76.89% <50.00%> (-4.93%) ⬇️
... and 4 more

... and 10 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 76.14% <55.07%> (-2.13%) ⬇️

ℹ️ Need help interpreting these results?

Comment thread .yamato/unified-tests.yml
@@ -34,11 +34,6 @@ unified_test_{{ project.name }}_{{ platform.name }}_{{ editor }}:
UNIFIED_TESTS: "true"

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.

Will we still need this to run those test?

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.

Ok, I saw that yes. In theory would be nice if those tests would run by default without any specific variable (which I guess will be true once we bump our minimal dependency on N4E to 7.2.0 right? And then we can remove this job)

@NoelStephensUnity NoelStephensUnity Oct 8, 2026 •

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.

Yes. But it has caveats.
The purpose behind the unified tests is that there are more tests that we "opt out" of running as hybrid than "opt-in". It is possible, but I am marking that down as a follow up PR to this one (to avoid delaying this from merging).

Noel-Bot 🤖 has a plan that is being vetted. If you want can create a Jira ticket as a follow up to this PR with any other conditions to make that possible? Otherwise, it will be added to my "pre-GA release things to do". 👍

"com.unity.ide.visualstudio": "2.0.26",
"com.unity.mathematics": "1.4.0",
"com.unity.multiplayer.tools": "2.2.11",
"com.unity.netcode": "https://github.cds.internal.unity3d.com/unity/unity.git?path=Workspace/com.unity.netcode#netcode/remove-exp-define-ghost-object",

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.

Should we make the same change to minimalproject and Examples/ ?

@NoelStephensUnity NoelStephensUnity Oct 9, 2026 •

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.

Good call out for sure!

Once PR-130027 lands we can update those projects since we will have to update test project to point to trunk anyway.

Once v7.2.0 is published and packman is resolving it, before we publish v3.2.0 we will want to make any changed manifest file(s) point to the version instead of the git URI.

…-n4e-experimental-define

# Conflicts:
#	.yamato/unified-tests.yml
…malproject

NGO now applies the NetcodeConfig values it needs at session start, so nothing in either asset is required.
Netcode for Entities creates the asset and its project settings entry on first open. The settings file is
removed too, since keeping it tracked would make every fresh checkout rewrite it.
…n first open

The assets are no longer tracked, so the files N4E writes when a project opens would otherwise show up
as untracked changes and could be committed back.
@NoelStephensUnity

Copy link
Copy Markdown
Member Author

@u-pr can you review this again please?

@u-pr

u-pr Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Review Summary

The recent changes addressing the hybrid PlayerPrefab registration during session startup cleanly resolve the earlier startup rejection issue. The accompanying tests in UnifiedHybridPrefabValidationTests provide solid coverage for both the rejection of mid-session hybrid prefabs and the pre-start detection of player prefabs.

A few items were noted for consideration in this pass (with inline comments attached to the diff):

  1. Preprocessor define in NetcodeIntegrationTest.cs:

    • In lines 747, 766, and 1975, #if UNIFIED_NETCODE_7_0_0 && UNITY_EDITOR was replaced with #if UNITY_EDITOR rather than #if UNIFIED_NETCODE && UNITY_EDITOR.
    • Because MultiplayerPlayModePreferences.WarnBatchedTicks is specific to Netcode for Entities, keeping UNIFIED_NETCODE in the preprocessor directive ensures this block is only compiled when Netcode for Entities 7.2+ is active, avoiding missing symbol errors on projects without N4E or on older supported Unity versions.
  2. Null-conditional operators (?.) on UnityEngine.Object:

    • In NetworkRigidBodyBase.cs (line 292, NetworkTransform?.UnregisterRigidbody()) and UnifiedNetcodeTransport.cs (line 491, m_NetworkManager?.NetcodeWorld), ?. bypasses Unity's overloaded equality operators. If either object is in a destroyed state (e.g. during scene transitions or teardown), ?. evaluates the CLR reference as non-null. Maintaining explicit != null or boolean checks (as was preserved in NetworkVariableBase.cs) avoids potential MissingReferenceExceptions.

🤖 Helpful? 👍/👎

Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkRigidBodyBase.cs Outdated
…l propagation

Implicit bool checks instead of ?. on NetworkTransform and NetworkManager, which the Standards formatter
does not rewrite.
@NoelStephensUnity

Copy link
Copy Markdown
Member Author

🤖 Acted on 2: NetworkRigidBodyBase and UnifiedNetcodeTransport.Shutdown now use Unity's implicit bool check instead of ?., a form the Standards formatter leaves alone (it rewrites != null back to ?.). Not 1: the UNITY_EDITOR-only guard matches what the old 7.0.0 define resolved to; see the thread on NetcodeIntegrationTest.cs.

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.

2 participants