--- name: unity-agent-workflow description: "How an AI coding agent works inside a Unity project so its changes are verifiable: the ladder (engine-free tests, offline compile check, Unity Test Framework, live Editor checks), the rules that keep Unity repos safe for agents (no hand-written scene/prefab/asset YAML, .meta files kept with their assets, Humble Object logic, domain reload), repo setup for agents, Unity's AI-content policy, and game design before code (one-pager, beat chart, player metrics, enemies, camera, playtest). Use whenever the user asks how Claude, Copilot, Cursor or Codex should work with Unity, wants a Unity repo set up for AI agents, asks for the latest thinking on AI with Unity or why an agent edit broke a scene or .meta, starts a Unity game or designs a level, enemy, weapon, camera or playtest for one, or says 'refresh unity-agent-workflow' / 'is unity-agent-workflow stale'. The CLI is unity-agent-cli; batchmode and compile checks are unity-agent-headless; MCP servers are unity-agent-mcp; packages are unity-agent-packages." --- # Unity agent workflow (how to work in a Unity repo and prove it) Outcome: the agent's Unity change is made through a route that leaves evidence, verified at the lowest rung that can catch the mistake, and the repo carries the rules so the next agent does the same. ## Step 0: freshness (every use, one read) Read `evergreen.json` next to this file. If `verify_at_use` is true, re-check the listed `volatile_claims` before relying on them. If `contradiction` is set or today is on or after `next_due`, tell the user in one line, do the task with the current content, then run the refresh (`evergreen-refresh`) in the same session. If `tests.failing` is non-empty, say so in one line and run `evergreen-tune` after the task. Never block the task on a refresh unless the task depends on the stale claim. ## Step 1: read the repo's own rules first Look for `AGENTS.md`, `CLAUDE.md`, `.github/copilot-instructions.md`, a `CODEMAP.md`, and any `.claude/skills` or `.agents/skills` folders. Repo rules win over this skill. If none exist, offer the snippet in `references/AGENTS-snippet.md` (do not add it unasked). ## Step 2: the verification ladder (lowest rung that can catch the mistake) | Rung | Catches | Cost | How | |---|---|---|---| | 1. Engine-free unit tests | logic, math, state, determinism | seconds, Editor may be open | a `dotnet test` project that links `Assets/Scripts` sources with a small `UnityEngine` stub (Humble Object: rules in plain C#, MonoBehaviours as thin shells) | | 2. Offline compile check | every C# error in the player and editor assemblies | ~3 s, Editor may be open | `dotnet build Assembly-CSharp.csproj` with a system or Unity-bundled SDK (unity-agent-headless) | | 3. Unity Test Framework | Editor APIs, serialization, scene loading, play-mode behaviour | minutes, Editor closed (or live via the Pipeline package) | `unity test --mode EditMode|PlayMode` (unity-agent-cli) or batchmode `-runTests` | | 4. Live Editor checks | what it looks like and logs at runtime | seconds per call, Editor open with Pipeline | `unity recompile` + `console --level error`, `editor_play`, `capture_game_view --source screen`, `eval` for state (unity-agent-cli) | | 5. Human in the Editor | feel, art, UX | the user's time | describe the exact repro path | Rule: a red rung is never "pre-existing". When a test or compile check fails after a change, fix it or report it as failing with the output; do not label it pre-existing and move on, because unexamined red tests pile up and the ladder stops meaning anything. Tests that only restate the code (tautological asserts) do not count as a rung; a test must fail when the behaviour breaks. Recipe (state dump + replay fixture, rungs 3-4): the game writes plain-text state rows (id, actual, expected) at a set timestamp; a small recorded dataset replays with expected values saved in a file beside it. Diff the rows against that file in both live and replay modes, so the agent reads a short diff instead of screenshots or logs. Visual changes are verified by a capture round: the same named views before and after, a difference image per pair (threewright `tw diff`), pictures read first and numbers second, and a view file saved with every capture so a reported spot is reproduced at its exact view before anything changes. Snippets, motion-measuring tools and the floating-origin TAA trap: [references/capture-round.md](references/capture-round.md). Performance is verified like behaviour: a frame-time or allocation number from a capture against a stated budget, before and after, at the lowest rung that can produce it (rung 3: the Performance Testing package; rung 4: `ProfilerRecorder` counters written by the state-dump recipe). Procedure, marker table, code traps, settings keys, audio cost and the silent-sound check order: [references/performance.md](references/performance.md). Rule: `dotnet test` green is not a compile check for engine-side files; before claiming a rename or removal is safe, grep all of `Assets` for every affected symbol and run rung 2. ## Step 3: rules that keep a Unity repo safe for agents - Never hand-write or regex-edit `.unity`, `.prefab`, `.asset`, `.controller`, `.mat` YAML, and never touch them at all while an Editor has the project open. Generate or change them through an editor script, an importer that reads a text source, a `[MenuItem]` the user can run, `-executeMethod`, or the Pipeline commands. Practitioners and the Unity-MCP maintainers agree direct YAML emission is unreliable and token-hungry. - Every file under `Assets/` needs a `.meta`; commit them together and `git mv` them together. A file created outside the Editor gets its `.meta` on the next import (`AssetDatabase.Refresh`) or from a repo helper; never regenerate an existing `.meta` (the GUID is the asset's identity); replacing an asset's content keeps its `.meta`. With no Editor open, a new `.meta` is a copy of a neighbour's with a fresh GUID; sliced sprite sheets have more rules (L-002). - Commits: read `git status` before staging and stage only the files the task changed; opening content re-serializes scenes, prefabs and sprite atlases, so revert ones the task did not mean to touch, and never `git add -A`. No empty folders under `Assets/`: Git drops the folder, its `.meta` is orphaned and Unity deletes it on the next clone. Repo setup: Visible Meta Files, a Unity `.gitignore` (Library, Temp, Obj, Logs, UserSettings, builds), Git LFS for large binaries. - DOTS: profile first; a CPU-bound hot loop becomes a Burst job over NativeArrays inside the GameObject project, with no Entities. Suggest Entities only for huge static worlds, thousands of heavy simulated units, or predicted competitive netcode, and never a rewrite to ECS as a fix; a GPU-bound game gains nothing. Jobs never do file or network I/O, and Burst code touches no class instances. - Keep gameplay rules in plain C# classes with `System.Math`, injected data and `event Action<...>` outputs, so rung 1 reaches them. `UnityEngine` calls live in thin MonoBehaviours. - Content (cards, items, levels) comes from text sources through an importer; hand-edited generated assets are overwritten on the next import. Change the source and the importer together. - 3D models: when one must be made, found, captured or fixed and the polywright plugin is installed, ask polywright through its asset folder ([contract](https://github.com/m4bwav/polywright/blob/main/skills/polywright/references/contract.md)) with the `game-unity` target, then import the file from `out/` that `manifest.json` names. Import settings, rigs, LODs, texture packing per pipeline, batching, collision, styles and import automation: [references/3d-models.md](references/3d-models.md). - Look target ("make it look better"): collect reference screenshots of games with the wanted look, have an image model edit a Game view capture toward them (the artwright plugin or any image-edit model, refs attached), and get one image approved as the target. Then change one thing per pass (lighting and shadow strength first, then a shared material palette, then kit or asset-pack parts) and score each capture against the target with threewright's `tw look shot.png target.png --sheet s.png` (0-100 OKLab score with per-part penalties; works on any PNG). `--fit look.cube` gives a LUT: HDRP's Tonemapping External mode takes a .cube imported as a 3D texture, URP's Color Lookup takes a 2D strip texture, so convert before using it there. - Sound effects: when the sfxwright plugin is installed, hand it the game events, finish with `--dest unity`, then read its `sounds.json` for the picked files and `randomize` values. Import and playback stay in the project. Without it, use the project's own clips; these rules work alone. - Domain reload: any recompile, Play-mode entry, or package change restarts bridges and clears static state. Batch edits, then verify once. - Editor lock: batchmode and a second Editor cannot open a project the Editor holds; the Pipeline route is for the open Editor, batchmode for the closed one. - Unity 6 logs live per project in `/Logs/`; read `Editor.log` there, not the global one. - C# style: follow the repo's existing conventions and `.editorconfig` first, and never mix prefix schemes in one file. Hard rules regardless: file name equals the MonoBehaviour class name, one MonoBehaviour per file, ASCII-only identifiers, `[SerializeField] private` over public fields; `static`, `const` and `readonly` fields never serialize, so they never show in the Inspector. - Save systems and serialized fields: adding a field is safe; renaming or removing one silently drops data. Flag any change to a serialized or save-reachable type; rename a serialized field with `[FormerlySerializedAs("oldName")]` to keep its data. UI Toolkit names and USS classes are strings: search UXML, USS and C# together before renaming one. - Don't add asmdefs, DI containers, Addressables, or new packages without asking; they change compile units and import behaviour for everyone. ## Step 4: game features: design before code When the request is a new game or a game feature (a level, an enemy, a weapon, the player's movement, the camera), not a fix or a refactor, read [references/game-design.md](references/game-design.md) first (after Rogers, *Level Up!*). Before the first gameplay script, the repo gets a `docs/ONE-PAGER.md` with the core loop as a verb; check each new request against it and say in one line when one does not fit. Movement and level numbers live in one `PlayerMetrics` ScriptableObject that the controller and the level tools both read. Enemies get a card (archetype, speed against the player, tells, health in hits) before they get a model, and only one or two attack at once. `_Playground` and `_CombatArena` scenes and compiled-out debug cheats come before real levels. A Cinemachine 3 camera uses the 3.x component names, and a PlayMode test keeps the player in view along a path. Rung 5 is handed over as the page's playtest protocol and questionnaire, not as "please playtest". ## Step 5: tooling worth pointing at (verify state at refresh) - Claude Code: Unity's official plugin (`/plugin marketplace add Unity-Technologies/unity-agent-plugin`, then `/plugin install unity@unity-agent-plugin`) bundles the Unity-Technologies/skills set and keeps it updated (skills only; Editor control goes through the Unity CLI: `unity pipeline install`, check `unity status`; `unity mcp configure` for the MCP). Third-party marketplaces do not auto-update by default: `/plugin marketplace update unity-agent-plugin`. A Codex variant exists. - Unity-Technologies/skills (MIT, official): `npx skills@1.7.0 add Unity-Technologies/skills` gives `unity-cli`, `unity-package-management`, `ui` router with `ui-uitk` (UI Toolkit), `ui-ugui`, `ui-imgui`, `unity-pipeline`, rendering, 2D, audio, multiplayer, IAP, LevelPlay, `new-unity-project` and more (about 29 skills by 2026-10-30; the list grows, see the repo). `unity skill install ` does the same for the CLI skill. - nowsprinting/unity-coding-skills (Unlicense): test-first Unity skills (`plan-feature`, `fix-bug`, `run-tests`, `unity-yaml-editing-guide`, `test-designing-guide`); the test and scene skills depend on Rider's MCP. - Unity-Technologies/skills (`unity-cli` about 9.3K installs, `unity-package-management` about 8.0K on 2026-11-03; no outside PRs) is the most used pack; gamedev-skills/awesome-gamedev-agent-skills (router over 74 game-dev skills, about 7.5K installs each); wshobson/agents `unity-ecs-patterns` (about 12.3K, one DOTS skill in a general pack) the most used community one; Nice-Wolf-Studio/unity-claude-skills: 20 topic skills in a WHEN/WRONG/RIGHT/GOTCHA format. - Unity's own agentic path: Unity CLI + Pipeline (unity-agent-cli), `unity mcp` (unity-agent-mcp). Unity 6.6 makes Fast Enter Play Mode (no domain reload on play) the default; Unity 7 (public alpha since 2026-10-05, preview December 2026, release early 2027) is positioned around agent collaboration: CoreCLR only, code reloads instead of domain reloads, and text-serialized assets start with a `%UNITY` format-version line that older Editors refuse. - Benchmarks and verification research (no Unity agent benchmark exists yet): GameDevBench (arXiv 2602.11103, Godot only), replay-based verification of generated Unity code (arXiv 2603.07101). Use them for ideas, not as harnesses. ## Step 6: Unity's stance on AI-made work (for a hobby or commercial project) Unity's Terms (updated 2026-06-30) let automated tools act on your account under your responsibility, and ยง17.2 (ff) and (gg) let AI agents and MCP clients reach Unity Offerings only through "Authorized Agentic Access" that Unity runs or designates; Unity's support account said this covers cloud services, the Asset Store and online APIs, not a local Editor bridge (informal, no official FAQ). The Asset Store allows AI-generated content with disclosure in the AI description field and bans training on Store assets. Unity AI features (Assistant, Generators) need a Unity Cloud project and their own terms; nothing restricts a project from using agent-written code with a normal Unity licence. Say this in one line when the user asks about permission; don't lecture. ## Output For "how should the agent work here": the ladder rung(s) you will use for the task, the route for any asset change, and the evidence you will show. For "set up the repo": the files you propose to add (snippet, skills, csproj generation) and what each prevents. For a game feature: the design files written or updated first (one-pager, metrics asset, enemy card, beat chart) and the test or playtest step that checks them. ## While working: capture learnings If the user corrects you, the same error happens twice, a workaround is found, or an environment fact is discovered, write it to `LEARNINGS.md` now (format in MAINTENANCE.md; check existing entries first: add, update, retire, or nothing). If a learning proves a claim above wrong, fix it here, log it in `CHANGELOG.md`, and set `contradiction` in `evergreen.json`. ## YouTube videos Engine tutorials give steps and gotchas, but versions drift fast: docs first, video second. Use fetchwright's `yt.py read URL` (captions, chapters, `&t=` links; opt-in route) and `yt.py clip URL A-B "question"` (Gemini reads the screen for spans of 2 minutes or less). Cite the `&t=` link and check numbers against a written source: auto-captions drop decimals. ## Maintenance This skill is evergreen (topic: how AI agents work safely and verifiably in Unity projects; tier `moderate`, currently every 30d, next due 2026-10-06). Files: `evergreen.json` (state), [RESEARCH.md](RESEARCH.md) (findings and search plan), [CHANGELOG.md](CHANGELOG.md) (every change, with reasons), [LEARNINGS.md](LEARNINGS.md) (lessons), [TESTS.md](TESTS.md) and `evals/evals.json` (the cases that prove it and the runs). Protocol: MAINTENANCE.md (pointer to the installed evergreen plugin). Refresh with `evergreen-refresh`; test with `evergreen-test`; fix a failure with `evergreen-tune`; audit with `evergreen-audit`. Sibling skills in this suite: unity-agent-cli, unity-agent-headless, unity-agent-mcp, unity-agent-workflow, unity-agent-packages.