Skip to content

Commit 3317eb1

Browse files
authored
Merge pull request #934 from Scriptwonder/bug-fix-and-doc-update-0315
Bug-Fix and Doc-Update
2 parents 189b983 + 33892fb commit 3317eb1

File tree

20 files changed

+1082
-145
lines changed

20 files changed

+1082
-145
lines changed

.claude/skills/unity-mcp-skill/SKILL.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@ Before applying a template:
2424
2. Understand the scene → mcpforunity://scene/gameobject-api
2525
3. Find what you need → find_gameobjects or resources
2626
4. Take action → tools (manage_gameobject, create_script, script_apply_edits, apply_text_edits, validate_script, delete_script, get_sha, etc.)
27-
5. Verify results → read_console, capture_screenshot (in manage_scene), resources
27+
5. Verify results → read_console, manage_camera(action="screenshot"), resources
2828
```
2929

3030
## Critical Best Practices
3131

32-
### 1. After Writing/Editing Scripts: Always Refresh and Check Console
32+
### 1. After Writing/Editing Scripts: Wait for Compilation and Check Console
3333

3434
```python
3535
# After create_script or script_apply_edits:
36-
refresh_unity(mode="force", scope="scripts", compile="request", wait_for_ready=True)
36+
# Both tools already trigger AssetDatabase.ImportAsset + RequestScriptCompilation automatically.
37+
# No need to call refresh_unity — just wait for compilation to finish, then check console.
38+
39+
# 1. Poll editor state until compilation completes
40+
# Read mcpforunity://editor/state → wait until is_compiling == false
41+
42+
# 2. Check for compilation errors
3743
read_console(types=["error"], count=10, include_stacktrace=True)
3844
```
3945

40-
**Why:** Unity must compile scripts before they're usable. Compilation errors block all tool execution.
46+
**Why:** Unity must compile scripts before they're usable. `create_script` and `script_apply_edits` already trigger import and compilation automatically — calling `refresh_unity` afterward is redundant.
4147

4248
### 2. Use `batch_execute` for Multiple Operations
4349

@@ -55,26 +61,35 @@ batch_execute(
5561

5662
**Max 25 commands per batch by default (configurable in Unity MCP Tools window, max 100).** Use `fail_fast=True` for dependent operations.
5763

64+
**Tip:** Also use `batch_execute` for discovery — batch multiple `find_gameobjects` calls instead of calling them one at a time:
65+
```python
66+
batch_execute(commands=[
67+
{"tool": "find_gameobjects", "params": {"search_term": "Camera", "search_method": "by_component"}},
68+
{"tool": "find_gameobjects", "params": {"search_term": "Player", "search_method": "by_tag"}},
69+
{"tool": "find_gameobjects", "params": {"search_term": "GameManager", "search_method": "by_name"}}
70+
])
71+
```
72+
5873
### 3. Use Screenshots to Verify Visual Results
5974

6075
```python
6176
# Basic screenshot (saves to Assets/, returns file path only)
62-
manage_scene(action="screenshot")
77+
manage_camera(action="screenshot")
6378

6479
# Inline screenshot (returns base64 PNG directly to the AI)
65-
manage_scene(action="screenshot", include_image=True)
80+
manage_camera(action="screenshot", include_image=True)
6681

6782
# Use a specific camera and cap resolution for smaller payloads
68-
manage_scene(action="screenshot", camera="MainCamera", include_image=True, max_resolution=512)
83+
manage_camera(action="screenshot", camera="MainCamera", include_image=True, max_resolution=512)
6984

7085
# Batch surround: captures front/back/left/right/top/bird_eye around the scene
71-
manage_scene(action="screenshot", batch="surround", max_resolution=256)
86+
manage_camera(action="screenshot", batch="surround", max_resolution=256)
7287

7388
# Batch surround centered on a specific object
74-
manage_scene(action="screenshot", batch="surround", look_at="Player", max_resolution=256)
89+
manage_camera(action="screenshot", batch="surround", look_at="Player", max_resolution=256)
7590

7691
# Positioned screenshot: place a temp camera and capture in one call
77-
manage_scene(action="screenshot", look_at="Player", view_position=[0, 10, -10], max_resolution=512)
92+
manage_camera(action="screenshot", look_at="Player", view_position=[0, 10, -10], max_resolution=512)
7893
```
7994

8095
**Best practices for AI scene understanding:**
@@ -87,10 +102,10 @@ manage_scene(action="screenshot", look_at="Player", view_position=[0, 10, -10],
87102
```python
88103
# Agentic camera loop: point, shoot, analyze
89104
manage_gameobject(action="look_at", target="MainCamera", look_at_target="Player")
90-
manage_scene(action="screenshot", camera="MainCamera", include_image=True, max_resolution=512)
105+
manage_camera(action="screenshot", camera="MainCamera", include_image=True, max_resolution=512)
91106
# → Analyze image, decide next action
92107

93-
# Alternative: use manage_camera for screenshot (same underlying infrastructure)
108+
# Screenshot from a different camera
94109
manage_camera(action="screenshot", camera="FollowCam", include_image=True, max_resolution=512)
95110
manage_camera(action="screenshot_multiview", max_resolution=480) # 6-angle contact sheet
96111
```
@@ -157,14 +172,14 @@ uri="file:///full/path/to/file.cs"
157172
|----------|-----------|---------|
158173
| **Scene** | `manage_scene`, `find_gameobjects` | Scene operations, finding objects |
159174
| **Objects** | `manage_gameobject`, `manage_components` | Creating/modifying GameObjects |
160-
| **Scripts** | `create_script`, `script_apply_edits`, `refresh_unity` | C# code management |
161-
| **Assets** | `manage_asset`, `manage_prefabs` | Asset operations |
175+
| **Scripts** | `create_script`, `script_apply_edits`, `validate_script` | C# code management (auto-refreshes on create/edit) |
176+
| **Assets** | `manage_asset`, `manage_prefabs` | Asset operations. **Prefab instantiation** is done via `manage_gameobject(action="create", prefab_path="...")`, not `manage_prefabs`. |
162177
| **Editor** | `manage_editor`, `execute_menu_item`, `read_console` | Editor control, package deployment (`deploy_package`/`restore_package` actions) |
163178
| **Testing** | `run_tests`, `get_test_job` | Unity Test Framework |
164179
| **Batch** | `batch_execute` | Parallel/bulk operations |
165180
| **Camera** | `manage_camera` | Camera management (Unity Camera + Cinemachine). **Tier 1** (always available): create, target, lens, priority, list, screenshot. **Tier 2** (requires `com.unity.cinemachine`): brain, body/aim/noise pipeline, extensions, blending, force/release. 7 presets: follow, third_person, freelook, dolly, static, top_down, side_scroller. Resource: `mcpforunity://scene/cameras`. Use `ping` to check Cinemachine availability. See [tools-reference.md](references/tools-reference.md#camera-tools). |
166181
| **Graphics** | `manage_graphics` | Rendering and post-processing management. 33 actions across 5 groups: **Volume** (create/configure volumes and effects, URP/HDRP), **Bake** (lightmaps, light probes, reflection probes, Edit mode only), **Stats** (draw calls, batches, memory), **Pipeline** (quality levels, pipeline settings), **Features** (URP renderer features: add, remove, toggle, reorder). Resources: `mcpforunity://scene/volumes`, `mcpforunity://rendering/stats`, `mcpforunity://pipeline/renderer-features`. Use `ping` to check pipeline status. See [tools-reference.md](references/tools-reference.md#graphics-tools). |
167-
| **Packages** | `query_packages` (read-only), `manage_packages` (mutating) | Install, remove, search, and manage Unity packages and scoped registries. `query_packages`: list installed, search registry, get info, ping, poll status. `manage_packages`: add/remove packages, embed for editing, add/remove scoped registries, force resolve. Validates identifiers, warns on git URLs, checks dependents before removal (`force=true` to override). See [tools-reference.md](references/tools-reference.md#package-tools). |
182+
| **Packages** | `manage_packages` | Install, remove, search, and manage Unity packages and scoped registries. Query actions: list installed, search registry, get info, ping, poll status. Mutating actions: add/remove packages, embed for editing, add/remove scoped registries, force resolve. Validates identifiers, warns on git URLs, checks dependents before removal (`force=true` to override). See [tools-reference.md](references/tools-reference.md#package-tools). |
168183
| **ProBuilder** | `manage_probuilder` | 3D modeling, mesh editing, complex geometry. **When `com.unity.probuilder` is installed, prefer ProBuilder shapes over primitive GameObjects** for editable geometry, multi-material faces, or complex shapes. Supports 12 shape types, face/edge/vertex editing, smoothing, and per-face materials. See [ProBuilder Guide](references/probuilder-guide.md). |
169184
| **UI** | `manage_ui`, `batch_execute` with `manage_gameobject` + `manage_components` | **UI Toolkit**: Use `manage_ui` to create UXML/USS files, attach UIDocument, inspect visual trees. **uGUI (Canvas)**: Use `batch_execute` for Canvas, Panel, Button, Text, Slider, Toggle, Input Field. **Read `mcpforunity://project/info` first** to detect uGUI/TMP/Input System/UI Toolkit availability. (see [UI workflows](references/workflows.md#ui-creation-workflows)) |
170185

@@ -173,14 +188,14 @@ uri="file:///full/path/to/file.cs"
173188
### Creating a New Script and Using It
174189

175190
```python
176-
# 1. Create the script
191+
# 1. Create the script (automatically triggers import + compilation)
177192
create_script(
178193
path="Assets/Scripts/PlayerController.cs",
179194
contents="using UnityEngine;\n\npublic class PlayerController : MonoBehaviour\n{\n void Update() { }\n}"
180195
)
181196

182-
# 2. CRITICAL: Refresh and wait for compilation
183-
refresh_unity(mode="force", scope="scripts", compile="request", wait_for_ready=True)
197+
# 2. Wait for compilation to finish
198+
# Read mcpforunity://editor/state → wait until is_compiling == false
184199

185200
# 3. Check for compilation errors
186201
read_console(types=["error"], count=10)

0 commit comments

Comments
 (0)