Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Unity?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/dotharness-unity)
---
name: unity
description: Inspect, automate, and debug a running Unity Editor. Use for Unity scenes, assets, project state, Console logs, and Editor C# execution.
---
# Unity
Use the `unity.*` tools to work with a running Unity Editor and execute C# on its main thread. Supports Unity 2021 through Unity 7 Alpha on Windows x64.
Load only the reference needed for the task:
- For loaded-type lookup and reflection helpers, read [references/api.md](references/api.md).
- For Console logs, read [references/console-reading.md](references/console-reading.md) and use the bundled script.
- For Editor, GameView, or SceneView images, or a specific camera viewpoint, read [references/editor-screenshot.md](references/editor-screenshot.md).
- For script compilation or reload, read [references/compilation-and-reload.md](references/compilation-and-reload.md).
- For snippet compilation errors, timeouts, or unexpected results, read [references/snippet-craft.md](references/snippet-craft.md).
## Connect
`unity.list` and `unity.status` are read-only and never inject or reconnect. Call `unity.list` when the target process is not already known. If several Editors are running, identify the intended one from its process information instead of guessing. Pass its `pid` to `unity.connect`; the result includes the Unity version, project path, Play Mode state, compilation state, and connection generation. That Editor remains selected for the current task.
Call `unity.status`, `unity.execute`, `unity.recompile`, and `unity.disconnect` without a PID. After a script reload, Attach recovers the bridge, and `unity.execute` and `unity.recompile` reconnect the selected Editor. Old executions and compiled contexts remain invalid. Do not replay the call that caused a reload. A new task must select its own Editor with `unity.connect(pid)`.
While the task has an Editor selected, your context includes a `## Unity Editor` block with the project, Editor version and PID, connection (ready, reloading scripts, recovering, or no longer running), Play Mode, and the latest script compilation with its errors. It is updated only when that state changes, so read it instead of polling `unity.status`. When the task disconnects or the Editor exits, the block says so once. When these tools run on a computer lent to your task, there is no such block; call `unity.status` when you need the state.
Use `unity.disconnect` to release this task's connection. It does not disconnect other clients or unload assemblies already loaded in the Editor.
## Execute C#
Pass exactly one of `code` or `path` to `unity.execute`. A path is resolved by the DotCraft host and can point to a bundled skill script or a workspace script.
The input consists of optional leading `using` directives followed by method-body statements. Do not wrap it in a namespace, class, or method. Return a compact string, anonymous object, or other JSON-serializable value. Common Unity value types such as vectors, colors, bounds, matrices, rays, and planes can be returned directly. A `UnityEngine.Object` returns its type, name, and identifier. Return an anonymous object to include more fields.
Use `args` for variable input. It is available to the snippet as a Newtonsoft `JObject` named `Args`:
```csharp
var name = (string)Args["name"] ?? "Player";
var target = GameObject.Find(name);
return new { found = target != null, name };
```
Use inline `code` for a short one-off operation. Store recurring project-specific snippets under `.craft/scripts/` and use `path`. Bundled scripts live under this skill's `scripts/` directory and can be passed by absolute path without copying them into the Unity project.
Snippets import `DotCraft.Unity`. The payload provides `Dcu.Type`, `Dcu.Components`, `Dcu.Get`, `Dcu.Set`, `Dcu.Call`, and `Dcu.Members` for loaded types and reflection-heavy inspection. Use ordinary Unity APIs directly when they are shorter.
### Await Editor updates
The snippet can use `await` directly. Use the provided `ctx` helpers when Unity work must continue on the Editor main thread:
```csharp
var before = System.Threading.Thread.CurrentThread.ManagedThreadId;
await ctx.WaitFrames(2);
return new {
before,
after = System.Threading.Thread.CurrentThread.ManagedThreadId,
scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name
};
```
Available helpers are `WaitFrame()`, `WaitFrames(int)`, `WaitSeconds(float)`, `WaitUntil(Func<bool>)`, `ThrowIfCancellationRequested()`, and `CancellationToken`. Prefer these helpers before accessing Unity APIs after an await. A general `Task` await may resume away from Unity's main thread when its synchronization context is bypassed.
### Run in the background
Pass `runInBackground: true` to let a long execution outlive the tool call. If it is still active after `yieldTimeMs`, `unity.execute` returns a `unity_<hex>` `executionId`. It is tracked as a standard DotCraft background task: when it finishes, DotCraft delivers a `<task_notification>` once with its result, so continue with other work instead of polling. Stop it with `TaskStop` (or `unity.wait` with `terminate: true`), and use `unity.wait` only to inspect or wait for it sooner.
Cancellation is cooperative. Waiting helpers observe it automatically, and longer synchronous loops should call `ctx.ThrowIfCancellationRequested()` or check `cancellationToken`. A running result with `cancellationRequested: true` means the code has not stopped yet. Do not replay an execution whose result is `unknown`.
## Work with the Editor
Inspect before mutating when the current state determines the safe change. For requested scene, asset, prefab, or settings edits, make the smallest bounded change, use Unity's `Undo` APIs where practical, mark modified objects deliberately, and report what changed. Save scenes or assets only when the request requires persistence.
Keep work in the background unless the user asks for visible interaction. Avoid opening or focusing windows, changing selection, showing dialogs, executing menu items, entering Play Mode, or triggering broad imports as incidental steps.
Do not block the Unity main thread with `Thread.Sleep` or long synchronous waits. Use the context helpers and background execution for work that spans Editor updates.
## Compile scripts
After editing project scripts, call `unity.recompile` once. It imports changed assets, compiles, and waits for bridge recovery after any resulting script reload, returning the compiler errors when compilation fails. Do not request compilation through `unity.execute`. See [references/compilation-and-reload.md](references/compilation-and-reload.md).
## Failures and reloads
A timeout can mean the code started but the result was not received. Inspect Editor state before deciding what happened and never replay the operation automatically.
`UnityAttachHandshakeTimeout` means the Editor's main thread did not answer: a long import, scene load, or hang is holding it. Attach cannot succeed until that ends, so do not retry it in a loop; measure the blocked Editor from outside it, or wait until it responds.
Snippet compilation errors report the failing C# diagnostics. Resolve ambiguous Unity and System type names with fully qualified names. Internal Unity APIs vary by version; inspect their members with reflection instead of repeatedly guessing signatures.
If an operation triggers a script reload, the old execution becomes `lost`. Attach establishes a new bridge. It never replays or resumes that execution. Wait for the `## Unity Editor` block to report the connection as ready, then verify the intended result with a fresh read-only call. If it reports that recovery failed, report the failure instead of repeatedly attaching.