-
Notifications
You must be signed in to change notification settings - Fork 505
[CUSTOM TOOLS] Roslyn Runtime Compilation Feature #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
* Update the .Bat file to include runtime folder * Fix the inconsistent EditorPrefs variable so the GUI change on Script Validation could cause real change.
String to Int for consistency
Allows users to generate/compile codes during Playmode
WalkthroughIntroduces a Roslyn-based runtime C# compilation framework for Unity MCP: new editor command handler (ManageRuntimeCompilation), a full-featured in-memory Roslyn compiler and EditorWindow (RoslynRuntimeCompiler), a Python MCP tool interface (runtime_compilation_tool), docs, and Unity asset metadata. Changes
Sequence Diagram(s)sequenceDiagram
actor Client as External MCP Client
participant PythonTool as runtime_compilation_tool.py
participant CmdHandler as ManageRuntimeCompilation
participant Compiler as RoslynRuntimeCompiler
participant Unity as Unity Engine
Client->>PythonTool: execute_with_roslyn(code, className, methodName, target, attach)
PythonTool->>CmdHandler: HandleCommand({action: "execute_with_roslyn", ...})
CmdHandler->>Compiler: CompileInMemory(source, refs)
Compiler->>Compiler: Parse & Emit DLL (in-memory)
Compiler-->>CmdHandler: {assemblyInfo, diagnostics}
alt attach == true
CmdHandler->>Compiler: AttachMonoBehaviour(targetGameObject)
Compiler->>Unity: Find GameObject -> Add/Replace component
Compiler-->>CmdHandler: {attached:true, runtimeResult}
else
CmdHandler->>Compiler: InvokeEntry(targetGameObject)
Compiler->>Compiler: Invoke static method or coroutine
Compiler-->>CmdHandler: {executed:true, runtimeResult}
end
CmdHandler->>Compiler: AddHistoryEntry(result)
CmdHandler-->>PythonTool: {success:true, data, diagnostics}
PythonTool-->>Client: {success:true, payload}
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🧰 Additional context used🧠 Learnings (5)📓 Common learnings📚 Learning: 2025-09-03T16:00:55.839ZApplied to files:
📚 Learning: 2025-10-13T13:41:00.086ZApplied to files:
📚 Learning: 2025-09-05T16:22:04.960ZApplied to files:
📚 Learning: 2025-09-05T16:22:04.960ZApplied to files:
🧬 Code graph analysis (2)CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs (2)
CustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs (1)
🪛 Ruff (0.14.3)CustomTools/RoslynRuntimeCompilation/runtime_compilation_tool.py30-30: Do not catch blind exception: (BLE001) Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs(1 hunks)CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs.meta(1 hunks)CustomTools/RoslynRuntimeCompilation/PythonTools.asset.meta(1 hunks)CustomTools/RoslynRuntimeCompilation/RoslynRuntime.md(1 hunks)CustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs(1 hunks)CustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs.meta(1 hunks)CustomTools/RoslynRuntimeCompilation/runtime_compilation_tool.py(1 hunks)CustomTools/RoslynRuntimeCompilation/runtime_compilation_tool.py.meta(1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 316
File: TestProjects/UnityMCPTests/Assets/Tests/EditMode/Resources.meta:1-8
Timestamp: 2025-10-13T13:27:23.040Z
Learning: UnityMcpBridge is a legacy project kept for backwards compatibility; MCPForUnity is the only active Unity plugin project. GUID collisions between UnityMcpBridge and MCPForUnity are acceptable.
📚 Learning: 2025-09-03T16:00:55.839Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 0
File: :0-0
Timestamp: 2025-09-03T16:00:55.839Z
Learning: ComponentResolver in UnityMcpBridge/Editor/Tools/ManageGameObject.cs is a nested static class within ManageGameObject, not a sibling type. The `using static MCPForUnity.Editor.Tools.ManageGameObject;` import is required to access ComponentResolver methods directly without the outer class qualifier.
Applied to files:
CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.csCustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs
📚 Learning: 2025-10-13T13:41:00.086Z
Learnt from: JohanHoltby
Repo: CoplayDev/unity-mcp PR: 309
File: MCPForUnity/Editor/Helpers/ServerInstaller.cs:478-508
Timestamp: 2025-10-13T13:41:00.086Z
Learning: In the MCPForUnityTools feature (MCPForUnity/Editor/Helpers/ServerInstaller.cs), the design intentionally forces users to have only one .py file per MCPForUnityTools folder to keep file tracking simple. Package-style tools (subdirectories with __init__.py) are not supported.
Applied to files:
CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs
🧬 Code graph analysis (2)
CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs (1)
CustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs (8)
System(82-92)System(683-687)CompileAndExecute(395-495)CompileAndExecute(500-505)SaveHistoryToFile(596-627)ClearHistory(677-681)RoslynRuntimeCompiler(44-688)RoslynRuntimeCompiler(700-720)
CustomTools/RoslynRuntimeCompilation/RoslynRuntimeCompiler.cs (1)
CustomTools/RoslynRuntimeCompilation/ManageRuntimeCompilation.cs (3)
RoslynRuntimeCompiler(508-524)GameObject(478-502)List(442-475)
🪛 Ruff (0.14.3)
CustomTools/RoslynRuntimeCompilation/runtime_compilation_tool.py
30-30: Do not catch blind exception: Exception
(BLE001)
Add several custom tools that MCP Servers can call to dynamically generate code during any mode.
Summary by CodeRabbit
New Features
Documentation
Bug Fixes