$npx -y skills add niqibiao/unity-cli-skill --skill unity-cliDrive the Unity Editor/Player from the command line via the C# Console service. Use for ANY Unity Editor automation: GameObject / component / transform / scene / prefab / material / asset / screenshot / profiler commands; executing raw C# in the live Editor; refreshing / recompil
| 1 | # Unity CLI |
| 2 | |
| 3 | One CLI (`cs`) drives everything; subcommands cover all operations. |
| 4 | Decision order for any task: **built-in command → snippet → raw exec**. |
| 5 | |
| 6 | ## Running `cs` |
| 7 | |
| 8 | `cs` below = `python "<SKILL_DIR>/scripts/cli/cs.py"`, where `<SKILL_DIR>` is THIS |
| 9 | skill's base directory (shown when the skill loads — an absolute path). Expand `cs` |
| 10 | to that full command on every call, and always pass `--json`. **Do not pass |
| 11 | `--project`** — the CLI auto-detects the Unity project (it walks up from the working |
| 12 | directory, and from its own committed location). Prefix with |
| 13 | `PYTHONDONTWRITEBYTECODE=1` so running the CLI leaves no `__pycache__` in the project: |
| 14 | |
| 15 | ```bash |
| 16 | PYTHONDONTWRITEBYTECODE=1 python "<SKILL_DIR>/scripts/cli/cs.py" command --json --input req.json |
| 17 | ``` |
| 18 | |
| 19 | No bootstrap/copy step — the CLI runs in place from this skill. First-time use needs the |
| 20 | **Unity package** in the project: `cs setup` installs it (see `references/setup.md`), and |
| 21 | `cs status` reports `NOT FOUND` until Unity resolves it. The first command auto-caches the |
| 22 | resolved package path (machine-local, under your home cache), so an explicit `cs setup` is |
| 23 | a convenience, not a gate. **`cs setup` writes the project's `Packages/manifest.json` — a |
| 24 | shared project file. Never run it (or `--update`) unprompted: tell the user what it will |
| 25 | write and get their go-ahead first.** |
| 26 | |
| 27 | ### Passing parameters — `--input` JSON (never inline) |
| 28 | |
| 29 | `command`, `exec`, `batch`, and `complete` take their params as a **single JSON object |
| 30 | written to a file** (or `-` for stdin), never as inline shell arguments. Write the JSON |
| 31 | with your file tool, then pass `--input <file>` — this removes all shell quoting/escaping |
| 32 | of C# code and nested JSON: |
| 33 | |
| 34 | ```bash |
| 35 | cs command --json --input req.json # req.json: {"ns":"gameobject","action":"create","args":{"name":"Cube"}} |
| 36 | cs exec --json --input req.json # req.json: {"code":"Debug.Log(\"hi\");"} |
| 37 | cs exec --json --file snippet.cs # exec also accepts raw C# from a .cs file |
| 38 | cs batch --json --input req.json # req.json: {"commands":[ … ],"stopOnError":true} |
| 39 | ``` |
| 40 | |
| 41 | ## Routing — pick the subcommand |
| 42 | |
| 43 | | Task | Subcommand | Detail | |
| 44 | |------|------------|--------| |
| 45 | | Structured editor ops (GameObject/component/scene/prefab/asset/material/screenshot/profiler) | `cs command --input` | references/commands.md | |
| 46 | | Raw C# in the live Editor (fallback) | `cs exec` | references/exec-code.md | |
| 47 | | Reusable C# snippet library | `cs snippets …` | references/snippets.md | |
| 48 | | Audit / validate snippets | `cs snippets doctor` / `stats` | references/snippets-audit.md | |
| 49 | | Refresh / recompile after writing .cs | `cs refresh` | references/refresh.md | |
| 50 | | Sync custom-command catalog / maintainer audit | `cs catalog sync` / `cs list-commands` | references/catalog.md | |
| 51 | | Connection / editor status | `cs status` / `cs health` | references/status.md | |
| 52 | | First-time package setup / version-check | `cs setup` | references/setup.md | |
| 53 | |
| 54 | ## Conventions (all subcommands) |
| 55 | |
| 56 | - Always `--json`; the envelope is `{ "ok", "exitCode", "summary", "data" }` — check |
| 57 | `ok` / `exitCode` for success. |
| 58 | - **Never pass `--project`** — the CLI auto-detects the project. Pass `--project <path>` |
| 59 | only to deliberately target a different project. |
| 60 | - Prefer `cs command` over `cs exec` when a built-in covers the task; check the snippet |
| 61 | library (`cs snippets search <desc>`) before falling back to ad-hoc `cs exec`. |
| 62 | - A `⚠ version mismatch` warning means the installed Unity package and the CLI are on |
| 63 | different `major.minor` lines — align them (see references/setup.md). It warns; it |
| 64 | does not block. |
| 65 | - `--json` and the expanded `python … cs.py …` command line are **agent-internal** — |
| 66 | for you to run and parse, never to paste to the user. When a step needs the user to |
| 67 | act (e.g. open Unity to resolve the package) and then re-verify, ask them in plain |
| 68 | language to **check unity-cli status**; run `cs status` yourself to read the result. |