9.7 KiB
| English | 简体中文 |
|---|
由 Coplay 荣誉赞助并维护 —— Unity 最好的 AI 助手。
用大语言模型创建你的 Unity 应用! MCP for Unity 通过 Model Context Protocol 将 AI 助手(Claude、Cursor、VS Code 等)与你的 Unity Editor 连接起来。为你的大语言模型提供管理资源、控制场景、编辑脚本和自动化任务的工具。
快速开始
前置要求
- Unity 2021.3 LTS+ — 下载 Unity
- Python 3.10+ 和 uv — 安装 uv
- 一个 MCP 客户端 — Claude Desktop | Cursor | VS Code Copilot | Windsurf
1. 安装 Unity 包
在 Unity 中:Window > Package Manager > + > Add package from git URL...
[!TIP]
https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity
想要最新的 beta 版本? 使用 beta 分支:
https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#beta
其他安装方式(Asset Store、OpenUPM)
Unity Asset Store:
- 访问 Asset Store 上的 MCP for Unity
- 点击
Add to My Assets,然后通过Window > Package Manager导入
OpenUPM:
openupm add com.coplaydev.unity-mcp
2. 启动服务器并连接
- 在 Unity 中:
Window > MCP for Unity - 点击 Start Server(会在
localhost:8080启动 HTTP 服务器) - 从下拉菜单选择你的 MCP Client,然后点击 Configure
- 查找 🟢 "Connected ✓"
- 连接你的客户端: 一些客户端(Cursor、Windsurf、Antigravity)需要在设置里启用 MCP 开关;另一些(Claude Desktop、Claude Code)在配置后会自动连接。
就这些! 试试这样的提示词:"Create a red, blue and yellow cube" 或 "Build a simple player controller"
功能与工具
关键功能
- 自然语言控制 — 指示你的大语言模型执行 Unity 任务
- 强大工具 — 管理资源、场景、材质、脚本和编辑器功能
- 自动化 — 自动化重复的 Unity 工作流程
- 可扩展 — 可与多种 MCP Client 配合使用
可用工具
manage_asset • manage_editor • manage_gameobject • manage_components • manage_material • manage_prefabs • manage_scene • manage_script • manage_scriptable_object • manage_shader • manage_vfx • batch_execute • find_gameobjects • find_in_file • read_console • refresh_unity • run_tests • get_test_job • execute_menu_item • apply_text_edits • script_apply_edits • validate_script • create_script • delete_script • get_sha
可用资源
custom_tools • unity_instances • menu_items • get_tests • gameobject • gameobject_components • editor_state • editor_selection • editor_prefab_stage • project_info • project_tags • project_layers
性能提示: 多个操作请使用 batch_execute — 比逐个调用快 10-100 倍!
手动配置
如果自动设置不生效,请把下面内容添加到你的 MCP Client 配置文件中:
HTTP(默认 — 适用于 Claude Desktop、Cursor、Windsurf):
{
"mcpServers": {
"unityMCP": {
"url": "http://localhost:8080/mcp"
}
}
}
VS Code:
{
"servers": {
"unityMCP": {
"type": "http",
"url": "http://localhost:8080/mcp"
}
}
}
Stdio 配置(uvx)
macOS/Linux:
{
"mcpServers": {
"unityMCP": {
"command": "uvx",
"args": ["--from", "mcpforunityserver", "mcp-for-unity", "--transport", "stdio"]
}
}
}
Windows:
{
"mcpServers": {
"unityMCP": {
"command": "C:/Users/YOUR_USERNAME/AppData/Local/Microsoft/WinGet/Links/uvx.exe",
"args": ["--from", "mcpforunityserver", "mcp-for-unity", "--transport", "stdio"]
}
}
}
多个 Unity 实例
MCP for Unity 支持多个 Unity Editor 实例。要将操作定向到某个特定实例:
- 让你的大语言模型检查
unity_instances资源 - 使用
set_active_instance并传入Name@hash(例如MyProject@abc123) - 后续所有工具都会路由到该实例
Roslyn 脚本验证(高级)
要使用能捕获未定义命名空间、类型和方法的 Strict 验证:
- 安装 NuGetForUnity
Window > NuGet Package Manager→ 安装Microsoft.CodeAnalysisv5.0- 同时安装
SQLitePCLRaw.core和SQLitePCLRaw.bundle_e_sqlite3v3.0.2 - 在
Player Settings > Scripting Define Symbols中添加USE_ROSLYN - 重启 Unity
手动 DLL 安装(如果 NuGetForUnity 不可用)
- 从 NuGet 下载
Microsoft.CodeAnalysis.CSharp.dll及其依赖项 - 将 DLL 放到
Assets/Plugins/目录 - 确保 .NET 兼容性设置正确
- 在 Scripting Define Symbols 中添加
USE_ROSLYN - 重启 Unity
故障排除
- Unity Bridge 无法连接: 检查
Window > MCP for Unity状态,重启 Unity - Server 无法启动: 确认
uv --version可用,并检查终端错误 - Client 无法连接: 确认 HTTP server 正在运行,并且 URL 与你的配置一致
详细的设置指南:
- Fix Unity MCP and Cursor, VSCode & Windsurf — uv/Python 安装、PATH 问题
- Fix Unity MCP and Claude Code — Claude CLI 安装
- Common Setup Problems — macOS dyld 错误、FAQ
还是卡住?开一个 Issue 或 加入 Discord
贡献
开发环境设置见 README-DEV.md。自定义工具见 CUSTOM_TOOLS.md。
- Fork → 创建 issue → 新建分支(
feature/your-idea)→ 修改 → 提 PR
遥测与隐私
匿名、注重隐私的遥测(不包含代码、项目名或个人数据)。可通过 DISABLE_TELEMETRY=true 关闭。详见 TELEMETRY.md。
许可证: MIT — 查看 LICENSE | 需要帮助? Discord | Issues
Star 历史
研究引用
如果你正在进行与 Unity-MCP 相关的研究,请引用我们!@inproceedings{10.1145/3757376.3771417,
author = {Wu, Shutong and Barnett, Justin P.},
title = {MCP-Unity: Protocol-Driven Framework for Interactive 3D Authoring},
year = {2025},
isbn = {9798400721366},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3757376.3771417},
doi = {10.1145/3757376.3771417},
series = {SA Technical Communications '25}
}
Coplay 的 Unity AI 工具
Coplay 提供 3 个 Unity AI 工具:
- MCP for Unity 在 MIT 许可证下免费提供。
- Coplay 是一个运行在 Unity 内的高级 Unity AI 助手,功能超过 MCP for Unity。
- Coplay MCP 是 Coplay 工具的“目前免费”版 MCP。
(这些工具有不同的技术栈。参见这篇博客文章:comparing Coplay to MCP for Unity。)
免责声明
本项目是一个免费开源的 Unity Editor 工具,与 Unity Technologies 无关。