Skip to content

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

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

jy-vivox wants to merge 10 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.

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.
@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
…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.
@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.03%   76.66%   +0.62%     
=================================================
  Files                159      159              
  Lines              27344    27344              
=================================================
+ Hits               20791    20963     +172     
+ Misses              6553     6381     -172     
Flag Coverage Δ
NGOv2_project_testproject_ubuntu 75.72% <ø> (+0.62%) ⬆️

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

see 16 files with indirect coverage changes

Components Coverage Δ
com.unity.netcode.gameobjects 76.66% <ø> (+0.62%) ⬆️

ℹ️ 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 2 commits October 23, 2026 09:52
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com>
…ibuted authority spawn refusal in the CLI queries (MTT-16534)

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