通过 MCP 客户端驱动正在运行的 Unreal Engine 编辑器,管理关卡、Actor、PIE 与控制台命令。
编程
unity-plugin
通过约 100 个工具控制 Unity 编辑器,覆盖场景、GameObject、输入模拟与 C# 代码执行。
它能做什么
在编辑器模式和播放模式下,通过约 100 个内置工具控制 Unity 编辑器,涵盖控制台、场景、GameObject、变换、组件、材质、预制体、资产、包管理、着色器、纹理、ScriptableObject、测试运行器、输入模拟以及编辑器状态。其中 script.execute 可在编辑器内执行任意 C# 代码,支持对静态方法和项目内类的反射调用,因此能改动场景、资产和设置。自 v1.6.3 起该技能默认 disableModelInvocation: true,只在用户明确请求时启动。
什么时候用它
- 查看场景层级和编辑器运行状态
- 创建与修改 GameObject、组件、材质和预制体
- 控制播放模式并模拟键盘、鼠标和 UI 输入以测试玩法
- 运行 EditMode/PlayMode 测试,并查询 Unity 包管理器
技能文档
Unity Plugin Skill
Control Unity Editor through ~100 built-in tools. Works in both Editor and Play mode.
Connection Modes
1. OpenClaw Gateway (Remote)
For Telegram, Discord, and other OpenClaw channels:
- Auto-connects when Unity opens
- Configure in: Window → OpenClaw Plugin → Settings
2. MCP Bridge (Local)
For Claude Code, Cursor, and local AI tools:
- Start: Window → OpenClaw Plugin → MCP Bridge → Start
- Default port: 27182
- Add to Claude Code:
claude mcp add unity -- node /MCP~/index.js
First-Time Setup
If unity_execute tool is not available, install the gateway extension:
# From skill directory
./scripts/install-extension.sh
# Restart gateway
openclaw gateway restart
The extension files are in extension/ directory.
What install-extension.sh Does
# 1. Copies extension files from skill to gateway
# Source: /extension/
# Destination: ~/.openclaw/extensions/unity/
# 2. Files installed:
# - index.ts # Extension entry point (HTTP handlers, tools)
# - package.json # Extension metadata
# After installation, restart gateway to load the extension.
🔐 Security: Model Invocation Setting
When publishing to ClawHub, disableModelInvocation controls who may start the skill:
| Setting | AI Auto-Invoke | User Explicit Request |
|---|---|---|
false (default) | ✅ Allowed | ✅ Allowed |
true | ❌ Blocked | ✅ Allowed |
Recommendation: true
Reason: this skill can execute arbitrary C# inside the Editor (script.execute)
and call Editor APIs by reflection. That is the whole point of it, and it is also
why it should never start on its own inference. As of v1.6.3 this skill ships with
disableModelInvocation: true — it runs only on explicit user request.
The full capability disclosure — arbitrary code execution, destructive operations, network surface — is in Security & Privacy Disclosure at the end of this document. Read it before enabling the skill.
Quick Reference
Core Tools
| Category | Key Tools |
|---|---|
| Scene | scene.getActive, scene.getData, scene.load, scene.open, scene.save |
| GameObject | gameobject.find, gameobject.getAll, gameobject.create, gameobject.destroy |
| Component | component.get, component.set, component.add, component.remove |
| Transform | transform.setPosition, transform.setRotation, transform.setScale |
| Debug | debug.hierarchy, debug.screenshot, console.getLogs |
| Input | input.clickUI, input.type, input.keyPress, input.mouseClick |
| Editor | editor.getState, editor.play, editor.stop, editor.refresh |
| Material | material.create, material.assign, material.modify, material.getInfo |
| Prefab | prefab.create, prefab.instantiate, prefab.open, prefab.save |
| Asset | asset.find, asset.copy, asset.move, asset.delete |
| Package | package.add, package.remove, package.list, package.search |
| Test | test.run, test.list, test.getResults |
Common Workflows
1. Scene Inspection
unity_execute: debug.hierarchy {depth: 2}
unity_execute: scene.getActive
2. Find & Modify Objects
unity_execute: gameobject.find {name: "Player"}
unity_execute: component.get {name: "Player", componentType: "Transform"}
unity_execute: transform.setPosition {name: "Player", x: 0, y: 5, z: 0}
3. UI Testing
unity_execute: input.clickUI {name: "PlayButton"}
unity_execute: input.type {text: "TestUser", elementName: "UsernameInput"}
unity_execute: debug.screenshot
4. Play Mode Control
unity_execute: editor.play # Enter Play mode
unity_execute: editor.stop # Exit Play mode
unity_execute: editor.getState # Check current state
unity_execute: editor.pause # Pause
unity_execute: editor.unpause # Resume
5. Material Creation
unity_execute: material.create {name: "RedMetal", color: "#FF0000", metallic: 0.8}
unity_execute: material.assign {gameObjectName: "Player", materialPath: "Assets/Materials/RedMetal.mat"}
unity_execute: material.modify {path: "Assets/Materials/RedMetal.mat", metallic: 1.0, emission: "#FF4444"}
6. Prefab Workflow
unity_execute: prefab.create {gameObjectName: "Player", path: "Assets/Prefabs/Player.prefab"}
unity_execute: prefab.instantiate {prefabPath: "Assets/Prefabs/Player.prefab", x: 0, y: 1, z: 0}
unity_execute: prefab.open {path: "Assets/Prefabs/Player.prefab"}
unity_execute: prefab.save
unity_execute: prefab.close
7. Asset Management
unity_execute: asset.find {query: "Player", type: "Prefab"}
unity_execute: asset.copy {sourcePath: "Assets/Prefabs/Player.prefab", destPath: "Assets/Backup/Player.prefab"}
unity_execute: asset.move {sourcePath: "Assets/Old/Item.prefab", destPath: "Assets/New/Item.prefab"}
8. Package Management
unity_execute: package.list
unity_execute: package.search {query: "TextMeshPro"}
unity_execute: package.add {packageName: "com.unity.textmeshpro"}
unity_execute: package.add {gitUrl: "https://github.com/example/package.git"}
9. Test Running
unity_execute: test.list {testMode: "EditMode"}
unity_execute: test.run {testMode: "EditMode", filter: "PlayerTests"}
unity_execute: test.getResults
10. Script Execution (Enhanced)
# Debug logging
unity_execute: script.execute {code: "Debug.Log('Hello')"}
# Time manipulation
unity_execute: script.execute {code: "Time.timeScale = 0.5"}
# PlayerPrefs
unity_execute: script.execute {code: "PlayerPrefs.SetInt('score', 100)"}
# Reflection-based method calls
unity_execute: script.execute {code: "MyClass.MyMethod()"}
unity_execute: script.execute {code: "MyClass.MyStaticMethod('param1', 123)"}
Tool Categories (~100 tools)
Console (3 tools)
console.getLogs- Get logs with optional type filter (Log/Warning/Error)console.getErrors- Get error/exception logs (with optional warnings)console.clear- Clear captured logs
Scene (7 tools)
scene.list- List scenes in build settingsscene.getActive- Get active scene infoscene.getData- Get full hierarchy datascene.load- Load scene by name (Play mode)scene.open- Open scene in Editor modescene.save- Save active scene (Editor mode)scene.saveAll- Save all open scenes (Editor mode)
GameObject (8 tools)
gameobject.find- Find by name, tag, or componentgameobject.getAll- Get all GameObjects with filteringgameobject.create- Create object or primitive (Cube, Sphere, etc.)gameobject.destroy- Destroy objectgameobject.delete- Delete object (alias for destroy)gameobject.getData- Get detailed datagameobject.setActive- Enable/disablegameobject.setParent- Change hierarchy
Transform (6 tools)
transform.getPosition- Get world position {x, y, z}transform.getRotation- Get Euler rotation {x, y, z}transform.getScale- Get local scale {x, y, z}transform.setPosition- Set world position {x, y, z}transform.setRotation- Set Euler rotationtransform.setScale- Set local scale
Component (5 tools)
component.add- Add component by type namecomponent.remove- Remove componentcomponent.get- Get component data/propertiescomponent.set- Set field/property valuecomponent.list- List available component types
Script (3 tools)
script.execute- Execute code: Debug.Log, Time, PlayerPrefs, reflection callsscript.read- Read script filescript.list- List project scripts
Application (4 tools)
app.getState- Get play mode, FPS, timeapp.play- Enter/exit Play modeapp.pause- Toggle pauseapp.stop- Stop Play mode
Debug (3 tools)
debug.log- Write to consoledebug.screenshot- Capture screenshotdebug.hierarchy- Text hierarchy view
Editor (9 tools)
editor.refresh- Refresh AssetDatabase (triggers recompile)editor.recompile- Request script recompilationeditor.domainReload- Force domain reloadeditor.focusWindow- Focus window (game/scene/console/hierarchy/project/inspector)editor.listWindows- List open windowseditor.getState- Get editor stateeditor.play- Enter Play modeeditor.stop- Exit Play modeeditor.pause/editor.unpause- Pause control
Input Simulation (10 tools)
input.keyPress- Press and release keyinput.keyDown/input.keyUp- Hold/release keyinput.type- Type text into fieldinput.mouseMove- Move cursorinput.mouseClick- Click at positioninput.mouseDrag- Drag operationinput.mouseScroll- Scroll wheelinput.getMousePosition- Get cursor positioninput.clickUI- Click UI element by name
Material (5 tools) - NEW in v1.5.0
material.create- Create material with shader, color, metallic, smoothnessmaterial.assign- Assign material to GameObjectmaterial.modify- Modify material properties (color, metallic, emission)material.getInfo- Get detailed material info with all shader propertiesmaterial.list- List materials in project with filtering
Prefab (5 tools) - NEW in v1.5.0
prefab.create- Create prefab from scene GameObjectprefab.instantiate- Instantiate prefab in scene with positionprefab.open- Open prefab for editingprefab.close- Close prefab editing modeprefab.save- Save currently edited prefab
Asset (7 tools) - NEW in v1.5.0
asset.find- Search assets by query, type, folderasset.copy- Copy asset to new pathasset.move- Move/rename assetasset.delete- Delete asset (with trash option)asset.refresh- Refresh AssetDatabaseasset.import- Import/reimport specific assetasset.getPath- Get asset path by name
Package Manager (4 tools) - NEW in v1.5.0
package.add- Install package by name or git URLpackage.remove- Remove installed packagepackage.list- List installed packagespackage.search- Search Unity package registry
Test Runner (3 tools) - NEW in v1.5.0
test.run- Run EditMode/PlayMode tests with filteringtest.list- List available teststest.getResults- Get last test run results
Batch Execution (1 tool) - NEW in v1.6.0
batch.execute- Execute multiple tools in one call (10-100x performance)commands: Array of {tool, params} objectsstopOnError: Stop on first error (default: false)
Session (1 tool) - NEW in v1.6.0
session.getInfo- Get session info (project, processId, machineName, sessionId)
ScriptableObject (6 tools) - NEW in v1.6.0
scriptableobject.create- Create new ScriptableObject assetscriptableobject.load- Load and inspect ScriptableObject fieldsscriptableobject.save- Save ScriptableObject changesscriptableobject.getField- Get specific field valuescriptableobject.setField- Set field value with auto-savescriptableobject.list- List ScriptableObjects in project
Shader (3 tools) - NEW in v1.6.0
shader.list- List shaders in projectshader.getInfo- Get shader properties and infoshader.getKeywords- Get shader keywords
Texture (5 tools) - NEW in v1.6.0
texture.create- Create new texture with color filltexture.getInfo- Get texture info (size, format, import settings)texture.setPixels- Fill region with colortexture.resize- Resize texture via import settingstexture.list- List textures in project
Custom Tools API - v1.6.0
Register project-specific tools:
OpenClawCustomTools.Register(
"mygame.getScore",
"Get current score",
(args) => new { success = true, score = GameManager.Score }
);
MCP Resources - v1.6.0
Access Unity data via MCP resource URIs:
| URI | Description |
|---|---|
unity://scene/hierarchy | Scene hierarchy |
unity://scene/active | Active scene info |
unity://project/scripts | Script list |
unity://project/scenes | Scene list |
unity://editor/state | Editor state |
unity://console/logs | Console logs |
unity://session/info | Session info |
Tips
Screenshot Modes
- Play mode:
ScreenCapture- includes all UI overlays - Editor mode:
Camera.main.Render()- no overlay UI - Use
{method: "camera"}for camera-only capture
Finding Objects
gameobject.find {name: "Player"} # By exact name
gameobject.find {tag: "Enemy"} # By tag
gameobject.find {componentType: "Camera"} # By component
gameobject.getAll {activeOnly: true} # All active objects
Script Recompilation
Unity may not auto-recompile after code changes. Use:
editor.refresh # Full asset refresh + recompile
Play Mode Transitions
- Plugin survives Play mode transitions via SessionState
- If connection lost, wait for auto-reconnect or use Window → OpenClaw Plugin → Settings → Connect
MCP Bridge Usage
For Claude Code / Cursor integration:
- Start: Window → OpenClaw Plugin → MCP Bridge → Start
- Register:
claude mcp add unity -- node /path/to/MCP~/index.js - Verify:
curl http://127.0.0.1:27182/status
Input Simulation Limitation
Keyboard/mouse simulation works for UI interactions but NOT for Input.GetKey(). For gameplay testing:
- Use
transform.setPositionto move objects directly - Or migrate to Unity's new Input System
Troubleshooting
| Issue | Solution |
|---|---|
| Tool timeout | Check Unity is responding, try editor.getState |
| Gateway no connection | Check Window → OpenClaw Plugin → Settings |
| MCP no connection | Start MCP Bridge, verify port 27182 |
| Scripts not updating | Use editor.refresh to force recompile |
| Wrong screenshot | Use Play mode for game view with UI |
| MCP 504 timeout | Unity busy or MCP Bridge not started |
| Test Runner not found | Install com.unity.test-framework package |
Security & Privacy Disclosure
This skill drives a live Unity Editor — treat it like giving a collaborator editor access. Full disclosure of capabilities:
- Arbitrary code execution (by design):
script.executecompiles and runs C# inside the Unity process, and several tools use reflection to reach editor internals. This is the core of editor automation — it also means the skill can do anything the editor can. Only use in trusted, version-controlled projects. Ask the user to review C# snippets before running code they didn't write. - Destructive operations — confirm with the user before: deleting GameObjects/assets, saving scenes/projects, installing packages, simulating keyboard/mouse input, running
script.execute. - Package installation: Git-based package installs import external, unvetted code into the project. Verify the source URL with the user first.
- Metadata: the connection handshake includes machine name and process ID (used to route messages to the right editor instance). No other host information is collected or transmitted.
- Network surface: MCP bridge listens on localhost port 27182. Keep it bound to localhost; do not expose the port beyond the local machine or a trusted network.
- Trigger scope: routine-sounding requests ("clean up the scene", "save everything", "just try it") map to state-changing editor operations — confirm once before the first state-changing call in a session.
- Safety defaults:
disableModelInvocation: trueis set — the model cannot auto-invoke this skill; it runs only on explicit user request. Keep project backups / source control current before automation sessions.
Links
- Skill Repository: https://github.com/TomLeeLive/openclaw-unity-skill
- Plugin Repository: https://github.com/TomLeeLive/openclaw-unity-plugin
- OpenClaw Docs: https://docs.openclaw.ai
- MCP Setup Guide: See Plugin Repository → Documentation~/SETUP_GUIDE.md
License
Apache-2.0 — See LICENSE.md
常见问题
- 这个技能会自动启动吗?
- 不会。自 v1.6.3 起它默认 disableModelInvocation: true,只在用户明确请求时才会运行——文档推荐此设置,因为 script.execute 能执行任意 C# 并通过反射调用编辑器 API。
- script.execute 究竟能做什么?
- 在编辑器内执行 C# 代码,例如 Debug.Log、修改 Time.timeScale、写入 PlayerPrefs,并对项目内类的静态方法支持反射调用,因此可以改动场景、资产和设置。
- 怎么把它接到 AI 工具上?
- 远程渠道(Telegram、Discord 等)走 OpenClaw Gateway;本地工具(Claude Code、Cursor 等)启用 MCP Bridge,默认端口 27182,Claude Code 可用 `claude mcp add unity -- node /MCP~/index.js` 添加。
相关技能
通过 30 个内置工具驱动 Godot 4.x 编辑器,覆盖场景、节点、变换、输入模拟、截图和日志。
按命令族和 profile 选择合适的 OpenClaw CLI 命令,并校验执行结果。
集成公告源监控、签名校验与风险技能处置的 ClawSec 套装管理入口。
每周更新的 OpenClaw 技能精选合集,14 个分类共 11211+ 个技能。
把交易灵感变成可安装的 Simmer 预测市场技能