Unity C# Edit
Implement Unity C# changes with unity-cli as the primary write path. Prefer the smallest write primitive that keeps the change correct, and preserve Unity serialization, UI binding paths, and editor/runtime boundaries.
Use When
- The user intends to change C# behavior in
.cs files.
- The user wants to create or rewrite scripts (single or coordinated multi-file).
- The user asks for a symbol rename, member add/remove, or refactor.
- The user changes project or package settings as part of a code change.
Do Not Use When
- The task is read-only investigation; use
unity-csharp-navigate.
- The work targets Editor state inspection (console, profiler, packages); use
unity-editor-tools.
Preferred Flow
- Decide the write shape: symbol edit, full-file write, multi-file write, or settings change.
- Read only the minimum context with
read, get_symbols, find_symbol, or find_refs.
- Preview risky symbol edits with
apply: false.
- Apply with
refresh, waitForCompile, and updateIndex when later steps depend on clean diagnostics.
- Inspect
changedFiles, changedSymbols, and diagnostics; fix compilation issues before unrelated follow-up.
unity-cli raw get_symbols --json '{"path":"Assets/Scripts/Player.cs"}'
unity-cli raw rename_symbol --json '{"relative":"Assets/Scripts/Player.cs","namePath":"Player/Jump","newName":"Leap","apply":false}'
unity-cli raw apply_csharp_edits --json '{"files":[{"relative":"Assets/Scripts/IPlayerMover.cs","newText":"public interface IPlayerMover { void Move(); }\n"}],"validate":true,"apply":true,"waitForCompile":true,"updateIndex":true}'
unity-cli raw get_compilation_state --json '{}'
Examples
- "Implement dash cooldown in
PlayerController.cs and update the related tests."
- "Rename
Jump to Leap across the player package without breaking serialized field names."
- "Create a new editor utility script and change the matching project setting."
- "Refactor an interface, its implementation, and the tests in one coordinated write."
References
- runtime-checklist.md: connection and instance prerequisites.
- file-write-recipes.md: choosing between symbol edits, file writes, and multi-file writes.
- lsp-write-safety.md: preview-first edits,
namePath, and write-result checks.
- unity-implementation-guidelines.md: serialized fields, UI bindings, editor code, ScriptableObjects, SettingsProviders.
- settings-write-recipes.md: project and package settings safe-write recipes.
1---2name: unity-csharp-edit3description: Implement, fix, and refactor Unity C# code with unity-cli write tools. Use when the user wants to change behavior in .cs files, create or rewrite scripts, update multiple C# files together, rename a symbol, add or remove members, or change project or package settings as part of a code change. Do not use for read-only inspection with no planned edit; use `unity-csharp-navigate` instead.4---56# Unity C# Edit78Implement Unity C# changes with `unity-cli` as the primary write path. Prefer the smallest write primitive that keeps the change correct, and preserve Unity serialization, UI binding paths, and editor/runtime boundaries.910## Use When1112- The user intends to change C# behavior in `.cs` files.13- The user wants to create or rewrite scripts (single or coordinated multi-file).14- The user asks for a symbol rename, member add/remove, or refactor.15- The user changes project or package settings as part of a code change.1617## Do Not Use When1819- The task is read-only investigation; use `unity-csharp-navigate`.20- The work targets Editor state inspection (console, profiler, packages); use `unity-editor-tools`.2122## Preferred Flow23241. Decide the write shape: symbol edit, full-file write, multi-file write, or settings change.252. Read only the minimum context with `read`, `get_symbols`, `find_symbol`, or `find_refs`.263. Preview risky symbol edits with `apply: false`.274. Apply with `refresh`, `waitForCompile`, and `updateIndex` when later steps depend on clean diagnostics.285. Inspect `changedFiles`, `changedSymbols`, and `diagnostics`; fix compilation issues before unrelated follow-up.2930```bash31unity-cli raw get_symbols --json '{"path":"Assets/Scripts/Player.cs"}'32unity-cli raw rename_symbol --json '{"relative":"Assets/Scripts/Player.cs","namePath":"Player/Jump","newName":"Leap","apply":false}'33unity-cli raw apply_csharp_edits --json '{"files":[{"relative":"Assets/Scripts/IPlayerMover.cs","newText":"public interface IPlayerMover { void Move(); }\n"}],"validate":true,"apply":true,"waitForCompile":true,"updateIndex":true}'34unity-cli raw get_compilation_state --json '{}'35```3637## Examples3839- "Implement dash cooldown in `PlayerController.cs` and update the related tests."40- "Rename `Jump` to `Leap` across the player package without breaking serialized field names."41- "Create a new editor utility script and change the matching project setting."42- "Refactor an interface, its implementation, and the tests in one coordinated write."4344## References4546- [runtime-checklist.md](references/runtime-checklist.md): connection and instance prerequisites.47- [file-write-recipes.md](references/file-write-recipes.md): choosing between symbol edits, file writes, and multi-file writes.48- [lsp-write-safety.md](references/lsp-write-safety.md): preview-first edits, `namePath`, and write-result checks.49- [unity-implementation-guidelines.md](references/unity-implementation-guidelines.md): serialized fields, UI bindings, editor code, ScriptableObjects, SettingsProviders.50- [settings-write-recipes.md](references/settings-write-recipes.md): project and package settings safe-write recipes.