← 开源

Let AI Drive Unity, from Editor to Play Mode.

AI EngineeringGive agent toolsC#
增长势头
+-224 小时新增 Star-0.3%
610
Star
50
Fork
+4
本周
10
贡献者
创建于 2025-06-15 · 更新于 2026-12-04 · 今日第 28827 名
主要开发者
hatayamaf4-ikugo-onaichilab
README

Unity CLI Loop

English | 日本語



(Logo inspired by Daft Punk's Human After All album art)

Let an AI agent compile, test, and operate your Unity project from popular LLM tools via CLI.

Designed to keep AI-driven development loops running autonomously inside your existing Unity projects.

Important

  • What's New in V3 — no more Node.js setup or port management, the new hot-reload / pause-point tools, automatic CLI updates with per-project version selection, and improved connection stability
  • Migrating Custom Tools and Skills to V3 — for anyone who has written C# custom tools, or skills and scripts that call the uloop command. Everyone else migrates just by updating the package and the CLI

Concept

Unity CLI Loop is a Unity integration tool designed so that AI can drive your Unity project forward with minimal human intervention. Tasks that humans typically handle manually — compiling, running the Test Runner, checking logs, editing scenes, capturing windows to verify UI layouts, and even operating a freshly implemented feature to confirm it actually works — can all be carried out from LLM tools.

Unity CLI Loop is built around three core ideas:

  1. A self-hosted development loop where AI autonomously compiles, tests, inspects logs, and fixes issues — it can even pause execution at any source line without editing code and read the variables at that moment to pin down a cause. Method-body fixes can be applied instantly to the running game without waiting for a recompile. Uses compile, run-tests, get-logs, clear-console, pause-point, hot-reload.
  2. AI-driven Unity Editor operation — scene building, object manipulation, menu execution, and UI refinement from screenshots. Uses execute-dynamic-code, screenshot.
  3. PlayMode automated testing — AI clicks buttons, drags elements, presses keys, replays recorded input, and verifies game behavior. Uses simulate-mouse-ui, simulate-mouse-input, simulate-keyboard, replay-input, execute-dynamic-code, screenshot.

Official Unity CLI and uloop

The official Unity CLI (unity) and uloop are not competitors: they cover different parts of the work, so you can use both. The official Unity CLI handles everything around the project, from installing Editors and creating projects to licenses and CI builds and tests. uloop is built for the loop an AI agent runs inside an open Editor while it writes code, and there it goes further: it supports Unity 2022.3 and later, gives finer options for the same tasks, and adds tools for finding out why something went wrong.

The official Unity CLI also reaches into running development builds of the Player, including on devices. uloop works only in the Editor, and in exchange it takes care of the finer details there.

Same task, finer control

What you want to do Official Unity CLI (unity) Unity CLI Loop (uloop)
Use it on your Unity version Unity 6.0+ (with the com.unity.pipeline package) Unity 2022.3+
Run tests in the open Editor test run: filter by name (partial match), assembly, or category. It does not compile first: with the Editor in the background, a test edited after the last compile ran its old code (measured); run unity recompile first to pick up the edit. PlayMode tests need --async-tests, and test status is polled for the results. With unsaved changes in the open scene, a PlayMode run stopped at Unity's "Scene(s) Have Been Modified" prompt and stayed running until test cancel (measured) run-tests: filter by exact name, regex, class, or assembly; compiles changed scripts before the run, so the edited test ran its new code (measured); PlayMode tests return their results in one command (measured); rerun only the tests that failed or were inconclusive last time; choose to save unsaved scene changes, stop, or discard them before the run, and stopping or discarding raised no prompt (measured)
Change code without leaving Play Mode Methods marked [MethodReload] beforehand (public, returning void or IEnumerator), which can call newly added methods; also reaches development Players, including IL2CPP; a method without the attribute is left unchanged with no error, and a body that uses a newly added field fails to compile (measured) hot-reload: no attributes; method bodies, new members, and new classes, in Edit Mode and Play Mode; some members, such as constructors, still need a compile; Editor only; it applied both a tagged and an untagged method, and a newly added field (measured)
See and answer a modal dialog that blocks the Editor unity command editor dialog, unity command editor dialog answer <id> <button>: only Unity 7.0 and later Editors answer them (official CLI 1.3.0 release notes); not available on Unity 6000.5 (measured). On Unity 6000.5, unity status reported the Editor as unreachable, and a command that needs the main thread waited for its 60-second timeout before saying that a modal dialog is open, without its title or buttons (measured) get-dialogs lists it and press-dialog-button presses a button: Unity 2022.3+ on macOS and Windows; status reports the dialog there, and on every OS from Unity 6000.7; status returned the dialog's title, message, and buttons in about a second, another command stopped with BLOCKED_BY_DIALOG in about a second, and press-dialog-button closed it (measured)
Press keys in Play Mode runtime simulate_key: down, up, or press. In Editor Play Mode the Game view must have focus, and code in Update never sees the moment of a press (measured): WasPressedThisFrame stays false, while a key held with down shows in isPressed and input action callbacks fire simulate-keyboard: also hold a key for a set time, and release every held key at once; reached the game with the Editor in the background, and the game saw the press for several frames, so WasPressedThisFrame and action callbacks both saw it (measured); when a press is not seen while the Editor is in the background, the result says so in Warning
Use the mouse in Play Mode runtime simulate_pointer: move, down, up, or click at a point. In Editor Play Mode the Game view must have focus, and a move while the button is down releases it, so it cannot drag (measured) simulate-mouse-input: click, long-press, scroll, move by a delta, and check which 3D object a point hits without clicking; simulate-mouse-ui: click, long-press, and drag uGUI and UI Toolkit elements, and uGUI elements even behind an overlay that blocks raycasts; both work with the Editor in the background
Compile and read the errors unity recompile: waits for the compile and returns each error with its file, line, column, and code; run again with the errors still there and nothing changed, it returned only a note to read them with console get (measured) compile: returns the errors every time it runs, also when nothing has changed (measured), and adds NextActions for some errors, such as the assembly that declares a namespace the code cannot find
Open a project that has compile errors The Editor stops at Unity's "Enter Safe Mode?" prompt, where the Pipeline package does not load; unity status --until-ready kept reporting starting (measured) launch presses Ignore on the Safe Mode prompt (macOS and Windows) and keeps waiting, so compile can list the errors
Read the Console console get: a minimum severity, the newest entries, and following new entries with a cursor; each entry came with its stack trace, and no parameter leaves it out: the newest 20 logs from game code were 9,796 bytes with --result-only (measured) get-logs: filter by type, and search the text or a regex, including stack traces; stack traces only when asked (--include-stack-trace): the same 20 logs were 2,240 bytes, or 7,099 with stack traces (measured)
Capture the screen capture: the Game view, the Scene view, or any open Editor window; camera captures include Screen Space - Overlay UI on URP and HDRP; a single UI Toolkit element only on Unity 6000.7+; returns the PNG inline as base64 unless given --output-path: a Game view capture at the default 1280x720 was 42,231 bytes (measured) screenshot: the Game view or any Editor window (Console, Inspector, and so on), labeling clickable UI elements and 3D colliders with the coordinates to click, or a prefab rendered on its own; saves the PNG to a file and returns its path, in 827 bytes (measured)
Restart the Editor unity close, then unity open --until-ready launch -r: one command, and it waits until the Editor can take commands
Control Play Mode editor.playmode start / pause / stop control-play-mode: also step one frame at a time, and choose what happens to unsaved scene changes
Run C# in the Editor script eval: whole scripts with using lines, top-level methods and types, and await; --file runs a .cs file and --dry-run only compiles; script run runs a project .cs file with JSON arguments execute-dynamic-code: statements only, with no class or method wrappers, plus JSON parameters and await, and can wait through a domain reload the code triggers (--wait-for-domain-reload)
Read the scene scene get_hierarchy: a whole scene get-hierarchy: start from a GameObject or the current selection, and limit the depth

Only in uloop

What you want to do Unity CLI Loop (uloop)
Stop at a source line without editing code, and read the variables pause-point
Record the Game view or any Editor window as video, and read it as frame sheets instead of watching it record-video
Replay input recorded in Play Mode (recorded from the Editor's Recordings window) replay-input
Set the Game view resolution set-game-view-size
Show the Game view in the Device Simulator and pick the device game-view-mode

Where the official Unity CLI leads

What you want to do Official Unity CLI (unity)
Install and manage Unity Editors and modules unity install, unity editors, unity install-modules
Create a project unity projects create
Sign in and check licenses unity auth, unity license
Build players and run tests in CI unity build, unity test (JUnit reports, sharding, retries, code coverage)
Build through the Editor that already has the project open unity build --target
Record Profiler captures and memory snapshots diagnostics profiler_record, diagnostics memory_snapshot
Drive a running Player build unity command --runtime

Commands without the unity prefix are Editor-side commands of the com.unity.pipeline package, run with unity command.

A typical setup uses both: unity install and unity open to get the right Editor, uloop for the agent's loop of editing, compiling, testing, and checking the game in that Editor, and unity build / unity test in CI.

Compared against the official Unity CLI 1.3.0 and com.unity.pipeline 1.0.1 (December 2026). Rows marked (measured) were checked by running both tools in the Editor on macOS with Unity 6000.5.8f1 and Input System 1.20.0, and sizes are the bytes each command printed; the setup, the numbers, and what was not tested are in docs/unity-cli-comparison.md. Both tools change quickly; unity --help and unity command list what your version has.

Demos

Each clip is a real Claude Code session driving a small voxel game through uloop. Stretches where only the terminal changes are sped up; the game plays at real speed.

Launch Unity: launch

uloop launch opens the project in the Unity version it specifies and returns once the Editor can take commands.

clip-01-launch-en.mp4

Add a feature and test it: compile, run-tests

Claude adds a glowing torch block, builds the project with compile, and runs the EditMode tests with run-tests. It fixes the test that fails, then checks the torch at night in Play Mode.

compile.mp4

Change code during Play Mode: hot-reload

Claude adds a double jump and applies it with hot-reload without leaving Play Mode, then presses Space with simulate-keyboard to measure the jump heights.

hot-reload.mp4

Stop on a line and read that frame: pause-point

The first time water flows into a gap, pause-point stops the game on the line that decides a cell's new water level and returns that frame's local variables, fields, and call path. A watch expression then tracks the water level along the channel while the water advances one tick at a time.

pause-point.mp4

Run C# inside the game: execute-dynamic-code

execute-dynamic-code runs C# in the running game. Claude stacks ten glass blocks in front of the player, then renders a wide shot of the tower from a temporary camera.

execute-dynamic-code.mp4

Capture what the game shows: screenshot

Claude finds the lake with execute-dynamic-code, moves the camera high above it, and captures the view with screenshot, then hides the HUD and takes the shot again.

screenshot.mp4

Read the scene: get-hierarchy, find-game-objects

get-hierarchy returns the running scene's tree (saving it to a file when it is large), and find-game-objects reads the Player's components.

get-hierarchy.mp4

Press keys: simulate-keyboard

simulate-keyboard holds W through the Input System. The player walks off the bank into the lake, and a screenshot confirms the underwater view.

simulate-keyboard.mp4

Move and click the mouse: simulate-mouse-input

simulate-mouse-input moves the mouse gradually, the way a hand would, to break three blocks and fill the hole with water.

simulate-mouse-input.mp4

Quickstart

This guide installs three things — the CLI, the Unity package, and the skills — so that your LLM tool can drive Unity. You can install everything from the terminal or from the Unity UI; either path is complete on its own.

Before you begin

Make sure you have:

  • A Unity project on Unity 2022.3 or later
  • An LLM tool that can load skills, such as Claude Code or Codex

Note

Upgrading from V2: if the project has custom tools written against the V2 API, compile errors appear right after the V3 package is installed. This is expected. Do not fix them by hand: choose Ignore in Unity's Safe Mode prompt on startup, then press Migrate in the migration window that opens automatically (Window > Unity CLI Loop > Custom Tool Migration). See Migrating Custom Tools and Skills to V3 for the full procedure.

Note

macOS permissions: when Unity does not answer, uloop status looks at Unity's windows for a dialog that blocks it, and uloop get-dialogs / uloop press-dialog-button read and press that dialog; uloop launch can also answer Unity's Safe Mode prompt this way. Allow the app that runs uloop (your terminal or LLM tool) under System Settings > Privacy & Security > Accessibility; macOS does not ask for it. Without it uloop still works, but it cannot look in Unity's windows for dialogs or press them; Unity 6000.7 or later still reports its own dialogs to uloop status.

Install from the terminal

Step 1: Install the CLI

macOS, Linux (x86_64), Windows Git Bash:

On Linux, focus-window is not supported.

curl -fsSL https://raw.githubusercontent.com/hatayama/unity-cli-loop/main/scripts/install.sh | sh

Windows PowerShell:

irm https://raw.githubusercontent.com/hatayama/unity-cli-loop/main/scripts/install.ps1 | iex

Homebrew (macOS):

brew install hatayama/tap/uloop

Check that the install worked:

uloop -v

The install succeeded when the first line shows the CLI version (for example 3.0.1).

Automatic CLI updates

While you use it, the CLI checks for a newer release at most once a day and installs it; the new version takes effect from the next command.

  • Stay on one version: uloop update --to-version <version> installs that release and holds it there. Run uloop update to resume automatic updates.
  • Turn automatic updates off: set ULOOP_DISABLE_SELF_UPDATE=1 in the environment.
  • Homebrew installs never update themselves; use brew upgrade uloop (and brew pin uloop to hold a version).

Step 2: Install the Unity package

Run this in the root of your Unity project:

uloop package install

This adds the OpenUPM scoped registry and the io.github.hatayama.uloopmcp dependency to Packages/manifest.json. Add --version <x.y.z> to pin a specific version.

Then launch Unity. If Unity is already running, this focuses that window instead:

uloop launch

Once Unity is up, the package is installed into the project. The next step reads the skills from the installed package.

Step 3: Install the skills

Run the command for your LLM tool in the root of your Unity project:

# Claude Code
uloop skills install --claude

# Codex and other tools that read .agents/skills
uloop skills install --agents

# Install at the root of the Git repository that contains the Unity project
uloop skills install --claude --root git

# Install globally instead of into the project
uloop skills install --claude --global

# Sync into any directory (e.g. an external skill-package store)
uloop skills install --output-dir path/to/skills

Install from the Unity UI

Step 1: Install the Unity package

In Window > Package Manager, press "+", choose Add package from git URL, and enter:

https://github.com/hatayama/unity-cli-loop.git?path=/Packages/src
Installing from the OpenUPM scoped registry
  1. In Project Settings > Package Manager, add this entry to Scoped Registries:
Name: OpenUPM
URL: https://package.openupm.com
Scope(s): io.github.hatayama.uloopmcp
  1. In Window > Package Manager, select OpenUPM under My Registries and install Unity CLI Loop.

Step 2: Install the CLI

Open Window > Unity CLI Loop > Settings and press Install CLI:

You are done when the CLI version is shown and the button changes to Uninstall CLI:

Step 3: Install the skills

In the same Settings window, select your target — for example Claude Code, or Common (.agents) for Codex and other tools that read .agents/skills — and press Install Skills:

Working alongside V2 projects

Projects on the V2 package and V3 projects can coexist on the same machine. Keep the V3 CLI installed: in a V2 project, the uloop command automatically uses the V2 CLI (downloaded on first use; Node.js 22 or later is required).

Do not press Update CLI or Downgrade CLI in a V2 project's Settings window, and do not reinstall the V2 CLI with npm install -g uloop-cli. The old npm uloop would hide the V3 CLI. If that has already happened, run npm uninstall -g uloop-cli, then run the CLI installer from Step 1 of "Install from the terminal" again or press Install CLI in the Settings window.

That's it! After installing Skills, LLM tools can automatically handle instructions like these:

Your Instruction Skill Used by LLM Tools
"Launch Unity for this project" /uloop-launch
"Fix the compile errors" /uloop-compile
"Apply this fix right now without compiling" /uloop-hot-reload
"Run the tests and tell me why they failed" /uloop-run-tests + /uloop-get-logs
"Check the scene hierarchy" /uloop-get-hierarchy
"Play the game and bring Unity to the front" /uloop-control-play-mode + /uloop-focus-window
"Bulk-update prefab parameters" /uloop-execute-dynamic-code
"Take a screenshot of Game View and adjust the UI layout" /uloop-screenshot + /uloop-execute-dynamic-code
"Replay the recorded input" /uloop-replay-input
"Pause at this line and investigate the bug" /uloop-pause-point
All 21 Bundled Skills
  • /uloop-launch - Launch Unity with correct version
  • /uloop-status - Check whether Unity can take a command now, and cancel the command Unity is running when BUSY keeps rejecting commands
  • /uloop-compile - Execute compilation
  • /uloop-get-logs - Get console logs
  • /uloop-run-tests - Run tests
  • /uloop-hot-reload - Apply method-body changes to running code instantly, without recompiling
  • /uloop-clear-console - Clear console
  • /uloop-focus-window - Bring Unity Editor to front
  • /uloop-get-hierarchy - Get scene hierarchy
  • /uloop-find-game-objects - Find GameObjects
  • /uloop-screenshot - Capture EditorWindow
  • /uloop-pause-point - Pause execution at any line and capture variables
  • /uloop-set-game-view-size - Read and set the Game View custom resolution
  • /uloop-game-view-mode - Show or switch the Game view tab between Game view and Device Simulator, matching its orientation, or pick the simulated device
  • /uloop-record-video - Record the Game View or an Editor window and get back frame sheets and change numbers an agent can read; one command can record around an action
  • /uloop-simulate-mouse-ui - Simulate mouse click, long-press, and drag on PlayMode UI elements
  • /uloop-simulate-mouse-input - Simulate mouse input in PlayMode via Input System
  • /uloop-simulate-keyboard - Simulate keyboard input in PlayMode via Input System
  • /uloop-replay-input - Replay input recorded in the Recordings window during PlayMode
  • /uloop-control-play-mode - Control Play Mode
  • /uloop-execute-dynamic-code - Execute dynamic C# code
Direct CLI Usage (Advanced)

You can also call the CLI directly without using Skills:

# List available tools
uloop list

# Launch Unity project with correct version
uloop launch

# Launch with build target (Android, iOS, StandaloneOSX, etc.)
uloop launch -p Android

# Quit running Unity and restart
uloop launch -r

# Execute compilation
uloop compile

# Compile without waiting for Domain Reload
uloop compile --no-wait-for-domain-reload

# Apply the method bodies of changed .cs files to running code without recompiling
uloop hot-reload

# Get logs
uloop get-logs --max-count 10

# Run tests
uloop run-tests --filter-type all

# Execute dynamic code
uloop execute-dynamic-code --code 'using UnityEngine; Debug.Log("Hello from CLI!");'

Configuration for Claude Code

Claude Code runs shell commands inside a sandbox, and the sandbox blocks network access by default. The IPC connection to Unity is also affected, so uloop fails with UNITY_NOT_REACHABLE (connect: operation not permitted) at the moment it tries to connect — even when Unity itself is running fine.

Add uloop * to sandbox.excludedCommands in ~/.claude/settings.json to exclude uloop commands from the sandbox:

{
  "sandbox": {
    "excludedCommands": ["uloop *"]
  }
}

The pattern is matched against the command string as typed, so invocations starting with uloop are excluded. See docs/claude-code-sandbox.md for details and measured results.

How It Works

A uloop command reaches the Unity Editor through the following chain:

  • The global uloop dispatcher — the single entry point on PATH. It interprets the command and delegates it to the runner for the target project
  • uloop-project-runner — the per-project runner. The version to use is determined by each project's .uloop/project-runner-pin.json (the pin) and downloaded automatically into a per-version user cache, which is how multiple projects on different versions coexist on one machine → project runner pin details
  • The IPC server inside the Unity Editor — accepts connections from the runner, executes Unity APIs, and returns the results

The connection uses no TCP ports. It goes over a Unix domain socket on macOS/Linux and a named pipe on Windows, so there is no port to configure and no port collision with other Editor instances.

Design Philosophy

Unity CLI Loop does not chase tool count. With dynamic C# code execution (execute-dynamic-code), almost any Unity Editor operation can be accomplished through a single tool.

Too many tools make it harder for AI to choose the right one. And even when tools are packaged as Skills, each tool's description still consumes the context window. We believe keeping tools to the essential minimum is good design.

Dedicated tools exist only for operations that dynamic code execution cannot handle by nature — such as frame-spanning input simulation and screenshot capture — and for operations called so frequently in the development loop, like compile and get-logs, that generating C# code each time would waste tokens.

When you find yourself wanting a new dedicated tool, a Skill usually suffices. Write the routine operation down as SKILL.md instructions, a shell script, or a C# snippet passed to execute-dynamic-code, and the AI just invokes it. The skill body is loaded only at startup and nothing has to be regenerated per run, so the additional token cost is close to zero. See the Custom Tool Development Guide for how to build one.

Key Features

For detailed descriptions and usage examples of every tool, see the Tool Reference.

Development Loop Tools

  • compile - Run compilation and return errors and warnings
  • get-logs - Retrieve the same logs as the Console, filtered by type or search string
  • run-tests - Run Unity Test Runner (PlayMode / EditMode)
  • hot-reload - Apply method-body changes to running code instantly, without recompiling
  • pause-point - Pause PlayMode at any line without editing code and read the variables at that moment

Unity Editor Automation & Discovery Tools

  • clear-console - Clear the Console logs
  • find-game-objects - Search scene objects and inspect components
  • get-hierarchy - Retrieve the scene structure as JSON
  • focus-window - Bring the Unity Editor window to the front
  • screenshot - Save screenshots of EditorWindows or the Game View
  • set-game-view-size - Read and set the Game View custom resolution
  • game-view-mode - Show or switch the Game view tab between Game view and Device Simulator, matching its orientation, or pick the simulated device
  • record-video - Record the Game View or an Editor window to MP4 (WebM on Linux) and return frame sheets and per-frame change numbers; with ffmpeg, cut frames out afterward
  • control-play-mode - Play, stop, and pause Play Mode
  • execute-dynamic-code - Execute dynamic C# code

PlayMode Automated Testing Tools

  • simulate-mouse-ui - Simulate mouse operations on UI elements (via EventSystem)
  • simulate-mouse-input - Simulate mouse input via Input System
  • simulate-keyboard - Simulate keyboard input via Input System
  • replay-input - Replay input recorded in the Recordings window during PlayMode

Unity CLI Loop Extension Development

Add project-specific custom tools in a type-safe way without touching the core package. Ship a Skill/SKILL.md alongside your tool and AI agents discover it automatically.

For implementation steps and how to write Skills, see the Custom Tool Development Guide.

Other

Unity CLI Loop Files

UserSettings/UnityCliLoopSettings.json stores per-user editor settings and should always remain local-only.

The .uloop/ directory at the project root stores CLI cache, tool registry, and runtime outputs. Most of its contents are local-only, but some files can optionally be git-tracked for team sharing.

File Purpose Git-track?
project-runner-pin.json Project runner version contract used by the global dispatcher Optional
settings.tools.json Per-tool enable/disable preferences Optional
settings.skills.json Skill install location (Unity project root or Git repository root) Optional
tools.json Auto-generated CLI tool registry No
outputs/ Runtime outputs (test results, screenshots, hierarchy dumps) No

Tip

Recommended .gitignore pattern

**/.uloop/*
!**/.uloop/settings.tools.json
!**/.uloop/settings.skills.json

This ignores auto-generated files and runtime outputs while allowing team-shared configuration to be tracked. Remove a ! line if you don't need to share that setting (tool enable/disable preferences or the skill install location).

project-runner-pin.json does not need to be tracked: the Editor rewrites it every time it opens the project, and uloop falls back to the pin inside the installed package. Track it (add !**/.uloop/project-runner-pin.json) only if you run uloop commands that use the pinned runner in a fresh clone that has never been opened in Unity, such as on CI.

License

MIT License

排名相邻
同类项目

AI Rank iPhone 版

随时追踪 AI 模型榜单

在 App Store 下载