Skip to content

feat: add Unity CLI commands for Netcode for GameObjects (MTT-16534) - #4210

Open
jy-vivox wants to merge 19 commits into
develop-3.x.xfrom
feat/cli-commands-mtt-15537
Open

jy-vivox wants to merge 19 commits into
develop-3.x.xfrom
feat/cli-commands-mtt-15537

Conversation

@jy-vivox

Copy link
Copy Markdown

Purpose of this PR

Adds Unity CLI commands for Netcode for GameObjects, so agents and scripts can set up and drive an NGO
project through com.unity.pipeline (unity command <group> <name>).

25 commands, in netcode.gameobjects and its subgroups:

  • netcode.gameobjects: create a NetworkManager, make and register network prefabs, list prefabs,
    clients and spawned objects, get the network role, spawn, despawn and change ownership, and audit
    the project's network prefab setup.
  • netcode.gameobjects.session: start and stop a host, server or client.
  • netcode.gameobjects.config: read and set NetworkManager and transport settings, including the log level.
  • netcode.gameobjects.simulator: network simulator settings, presets, lag spikes and timeouts.
  • netcode.gameobjects.profiler: sample network traffic: bytes and messages sent and received, per message type.

The commands are in a separate editor assembly, Editor/CLI, that only compiles when
com.unity.pipeline 0.9.0-exp.1 or later is installed. NGO doesn't depend on the pipeline. The commands'
logic is in Editor/CliQueries, inside the existing editor assembly, so it is compiled and tested either way.

Simulator presets use Multiplayer Tools when it is installed: an optional reference with
a versionDefines entry (2.0.0 or later). Without it, the simulator commands use the transport's own
simulator settings.

Names follow the Netcode for Entities commands (netcode root), so both packages share one group root
and the same argument names.

Jira ticket

MTT-16534

Changelog

com.unity.netcode.gameobjects

  • Added: Unity CLI commands (netcode.gameobjects groups) to set up NetworkManagers and network prefabs, start and stop sessions, inspect clients and spawned objects, spawn, despawn and change ownership, simulate network conditions and sample network traffic. They are available when the project has com.unity.pipeline 0.9.0-exp.1 or later.

Documentation

  • Adds unity-cli-commands.md, with every command and its arguments, linked from the table of contents
    and from the testing and debugging page.

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

Editor 6000.7.0b1, minimalproject:

  • 46/46 pass with the pipeline installed, with or without Multiplayer Tools. Without the pipeline, 39/39 pass,
    and the command assembly is correctly skipped.
  • All 25 commands run live with two Editors, a host and a remote client (a copy of the project):
    • authoring: create_network_manager, make_prefab, register_prefab, list_prefabs, audit, config;
    • session: connect, wait_ready on both sides, list_clients;
    • objects: spawn (server-owned, client-owned, player object), change_owner, despawn, list_objects
      and get_object on both peers, and the client-side refusals;
    • kick, then reconnect; stop, change config, start again as a server;
    • profiler get_stats with traffic: the client recorded each spawn, ownership change and despawn message.
  • Simulator turned on in edit mode, before the client started: RTT went from 11 ms to 315 ms with a 150 ms
    delay. A lag spike, then a timeout that drops the client after the 30 s disconnect timeout, reconnect
    afterwards, and turning it off restores the RTT.
  • With Multiplayer Tools 2.2.11: presets listed and applied (RTT 71 ms), lag spike, timeout.

Live testing found three issues, fixed here:

  • get_stats read the profiler's Network counters, which stayed at zero. It now reads NGO's message hooks.
  • reconnect refused a client that had been kicked or timed out.
  • An error message left an unsaved scene's name blank.

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

Not needed: this targets develop-3.x.x.

Backports

None. The commands need the pipeline's command API from 0.9.0-exp.1.

@jy-vivox
jy-vivox marked this pull request as ready for review October 22, 2026 20:37

@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 CLI covers a broad range of authoring and runtime operations, but several edge cases diverge from NGO’s lifecycle and prefab semantics.

Reviewed commit 561afc4

🤖 Helpful? 👍/👎

Comment thread com.unity.netcode.gameobjects/Editor/CliQueries/NgoCliQueries.Authoring.cs Outdated
Comment thread com.unity.netcode.gameobjects/Editor/CliQueries/NgoCliQueries.cs
@codecov-github-com

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

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@                Coverage Diff                @@
##           develop-3.x.x    #4210      +/-   ##
=================================================
+ Coverage          76.25%   76.94%   +0.68%     
=================================================
  Files                159      159              
  Lines              27538    27581      +43     
=================================================
+ Hits               21000    21222     +222     
+ Misses              6538     6359     -179     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 76.01% <100.00%> (+0.68%) ⬆️

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

Files with missing lines Coverage Δ
...netcode.gameobjects/Runtime/Core/NetworkManager.cs 75.02% <100.00%> (+3.21%) ⬆️
...meobjects/Runtime/Transports/UTP/UnityTransport.cs 76.98% <100.00%> (+0.85%) ⬆️

... and 17 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 76.94% <38.55%> (+0.68%) ⬆️

ℹ️ Need help interpreting these results?

Comment thread com.unity.netcode.gameobjects/Documentation~/testing-debugging.md Outdated
Comment thread com.unity.netcode.gameobjects/Documentation~/unity-cli-commands.md Outdated
Comment thread com.unity.netcode.gameobjects/Documentation~/unity-cli-commands.md Outdated
jy-vivox and others added 17 commits October 28, 2026 12:16
Commands in the netcode.gameobjects groups for com.unity.pipeline 0.9.0 or later: set up
NetworkManagers and network prefabs, audit the project, start and stop sessions, inspect
clients and spawned objects, spawn, despawn and change ownership, simulate network
conditions and sample network traffic. The command assembly only compiles when the
pipeline package is installed; the logic lives in the editor assembly and is tested
without it.
A prerelease sorts below its release, so the 0.9.0 gate left the commands out of projects
with the published 0.9.0-exp.1.
Restore each transport's own simulator settings once the CLI simulator, timeout and lag spike
are off, and keep a timeout on through a lag spike. Gate the simulator presets on Multiplayer
Tools 2.0. Prefer an exact NetworkManager name, keep the transport protocol and WebSocket path
when setting the address, refuse address changes on Relay, and listen on every interface for a
remote address. Let the server own objects in client-server.
- register_prefab treats a prefab as registered when a list entry overrides it,
  matching entries by source prefab or prefab id hash as NGO does at runtime.
- audit reports override entries with no target, a target without a root
  NetworkObject, or a hash override with a zero source hash.
- audit, list_prefabs and register_prefab handle empty list entries; audit
  reports them as a LIST_ENTRY_INVALID warning.
- make_prefab refuses prefabs with child NetworkObjects instead of saving an
  unsupported network prefab.
- config set refuses spawn_timeout outside 10-3600 seconds, and NaN or infinite
  float values.
- profiler get_stats reads traffic from the message manager's hooks, as NGO's own
  metrics do: bytes and messages sent and received, per message type. The
  profiler's Network counters it read before stayed at zero in a live session.
- session reconnect connects a client again after it was kicked or timed out,
  instead of refusing because it had already shut down.
- Messages name an unsaved scene as such instead of leaving the name blank.
…ject commands (MTT-16534)

- config set records changes to a prefab instance as prefab overrides in edit mode.
- spawn refuses a distributed-authority client that hasn't connected yet, and destroys
  an instance a failed spawn leaves behind.
- get_stats ends with an error when the session stops or restarts while sampling.
- audit counts the open scenes' player prefabs as registered, and ignores the Prefab
  field a hash override keeps, as NGO does.
- get_object lists only the inspected object's own behaviours, not nested ones.
…Unity null checks in SourcePrefab (MTT-16534)

- Unity.Netcode.GameObjects.Editor.CLI becomes Unity.Netcode.GameObjects.CLI.Editor and its tests
  Unity.Netcode.GameObjects.CLI.Editor.Tests, as package validation (PVP-132-2) requires editor
  assemblies to end with .Editor and editor test assemblies with .Editor.Tests.
- SourcePrefab tests the override source with Unity's null check in a form the standards check
  accepts; its suggested ?? would skip that check for a missing reference.
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
…ibuted authority spawn refusal in the CLI queries (MTT-16534)
…t ports from the OS (MTT-16534)

- A [UnityTearDown] shuts down running NetworkManagers and exits play mode, so a failed assert no longer leaves the following edit mode tests in play mode.
- Enter play mode options are only changed (and restored) when they differ, so ProjectSettings/EditorSettings.asset isn't re-saved.
- The play mode tests bind a port the OS reports as free instead of a random one in 20000-40000.
…rned on, and warn in the console while it is (MTT-16534)

- UnityTransport.TransportInitialized is subscribed to only when the CLI simulator, a timeout or a lag spike is on, so projects that never use the CLI hook no transport event.
- While the simulator is on, the console warns once per play session, when it first changes a driver, with the delay, jitter and loss and how to turn it off. The settings outlast the play session that set them.
- The hook stays in the editor assembly: the query layer and its tests use it, and the CLI assembly only compiles with com.unity.pipeline.
…each a hybrid session (MTT-16534)

A session whose prefabs include GhostObject ones runs over Netcode for Entities' UnifiedNetcodeTransport on port 7979, not the NetworkManager's UnityTransport.
- simulator get and set add a note for such managers, and timeout and lag_spike refuse with that reason instead of asking for a session to be started.
- config set address, port and listen_address still save the value, with a note that it doesn't apply. session start skips its address and port override and says why.
- get_stats notes that GhostObject replication isn't counted.
- The audit's hybrid prefab lookup is shared as ConfiguredHybridPrefabs, so a session is recognized as hybrid before it starts.
- The docs add a Hybrid sessions section that points to Netcode for Entities' netcode.simulator and netcode.profiler commands.
…d only lift a blackout the CLI set (MTT-16534)

- config set address and session start --address move a default listen address with the connect address, as create_network_manager sets it, so a host on a LAN address listens on 0.0.0.0. A listen address set on purpose stays.
- reconnect refuses a host or server the CLI started and that has since stopped, instead of starting it again as a client.
- The simulator lifts leftover 100% packet loss only when the CLI applied it (tracked in SessionState), so loss set on purpose in a Network Simulator component stays.
- UnityTransport exposes an internal TransportId, used for its driver events and by the CLI simulator, instead of the simulator copying the computation.
- config set no longer creates a missing NetworkConfig before the dry-run check; it refuses instead.
…efab saves the list, and add the PR number to the changelog (MTT-16534)

- get_stats' docs and receive hook note that per-type received bytes can be up to 6 bytes a message high, because NetworkMessageManager reports the unpacked header size. Batch totals are exact.
- register_prefab's description and docs say it saves the list and creates the default list if needed.
- The CHANGELOG entry gets (#4210).
- Loops and List/Array methods (Find, FindAll, Exists, ConvertAll, GetRange) replace every Linq call in Editor/CliQueries and Tests/Editor/Cli.
- New helpers keep the output unchanged: StableSort keeps OrderBy's tie order for managers, spawned objects and stats messages. WithoutDuplicates keeps Distinct's first-seen order. JoinNames builds the comma-separated lists in messages.
- Session's IsConnected and CountOtherClients replace the hidden Linq Contains and Count on ConnectedClientsIds.
- NetworkManager keeps the role it last started as (internal LastStartedRole), so reconnect refuses a stopped host or server however it was started, and the CLI's own role dictionary, and its leak, is gone.
- The simulator forgets a blackout only once every live driver has been let through, so timeout false still lifts one left on after a script recompile in play mode.
- After a recompile in play mode, the simulator subscribes to new drivers again when it's on.
- The console warns again when the simulator settings change, instead of keeping the first values.
- config set address/port explains a hybrid session when the transport has already been swapped to UnifiedNetcodeTransport.
- A distributed authority manager isn't reported as hybrid, since that topology rejects hybrid prefabs.
- Start's doc comment is back on Start.
@jy-vivox
jy-vivox force-pushed the feat/cli-commands-mtt-15537 branch from 9498505 to 2318c21 Compare October 28, 2026 16:56
@cla-assistant-unity

cla-assistant-unity Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@simon-lemay-unity simon-lemay-unity 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.

UnityTransport changes look fine.

@NoelStephensUnity NoelStephensUnity left a comment

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.

Looks great John!
👍

jy-vivox and others added 2 commits October 28, 2026 15:24
…dards check (MTT-16534)

- UnifiedNetcodeTransport is written as Unified.UnifiedNetcodeTransport, since the tests' namespace is already under Unity.Netcode (IDE0001).
- The m_Hooks lookup uses BindingFlags directly now that the file has using System.Reflection (IDE0002).

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.

5 participants