Assembly loading issue with Claude Code
Closed this issue · 4 comments
The assembly loading issue is likely a bug where Unity MCP is trying to load the wrong assembly. Editor scripts go in "Assembly-CSharp-Editor" but runtime MonoBehaviour scripts should be in "Assembly-CSharp".
@WazzaF can you give some more detail on when you’re running into this? Like an example prompt you’re giving the MCP, and the errors you’re getting either from your AI client or the unity console or both? That would help us isolate the issue better.
Thanks @dsarno , please see the report below for detail:
Unity MCP Assembly Loading Error Report
Issue Summary
The Unity MCP server has an assembly loading bug where it attempts to load "Assembly-CSharp-Editor" instead of "Assembly-CSharp" when working with runtime MonoBehaviour scripts through MCP tool calls.
Error Details
Primary Error Message
System.IO.FileNotFoundException: Could not load the file 'Assembly-CSharp-Editor'
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at UnityMCP.ComponentResolver.ResolveComponent(String componentName)
at UnityMCP.GameObjectManager.AddComponent(GameObject target, String componentName)
Context
- Environment: Unity 6.2, Windows 10/11
- Project: Unity project with custom MonoBehaviour scripts
- Trigger: Adding custom script components to GameObjects via MCP tools
- Expected Behavior: Should load from "Assembly-CSharp" (runtime assembly)
- Actual Behavior: Attempts to load from "Assembly-CSharp-Editor" (editor assembly)
Technical Analysis
Root Cause
The MCP server appears to have incorrect assembly resolution logic that:
- Defaults to looking in editor assemblies for runtime components
- Does not fall back to runtime assemblies when editor assembly fails
- May be using editor-specific reflection paths during runtime operations
Assembly Structure in Unity
Correct Assembly Mapping:
├── Assembly-CSharp (Runtime)
│ ├── MonoBehaviour scripts
│ ├── ScriptableObject scripts
│ └── Runtime-only classes
└── Assembly-CSharp-Editor (Editor Only)
├── Editor scripts
├── Custom inspectors
└── Editor utilities
Reproduction Steps
- Create a custom MonoBehaviour script (e.g.,
PlayerController.cs) - Place script in
Assets/Scripts/folder (runtime location) - Use MCP tool to create GameObject
- Attempt to add the custom component via MCP
- Error occurs during component resolution
Workarounds Currently Used
- Manual Assignment: Create GameObject via MCP, manually assign components in Inspector
- Built-in Components Only: Use Unity's built-in components through MCP
- Script Creation First: Create scripts via MCP, then manual component assignment
Expected Fix
The assembly resolution should:
- First attempt to load from
Assembly-CSharp(runtime assembly) - Fall back to
Assembly-CSharp-Editoronly for editor-specific components - Provide clear error messages distinguishing between assembly types
Sample Code That Fails
// This script exists in Assets/Scripts/PlayerController.cs
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 5.0f;
void Update()
{
// Runtime logic here
}
}MCP Call:
{
"action": "add_component",
"target": "Player",
"component_name": "PlayerController"
}Result: FileNotFoundException: Could not load the file 'Assembly-CSharp-Editor'
Additional Context
- Project has been built successfully with
./build.sh - Scripts compile without errors in Unity Editor
- Manual component assignment works perfectly
- Issue only occurs when using MCP automation tools
System Information
- Unity Version: 6.2
- Platform: Windows
- .NET Version: .NET Standard 2.1
- Project Type: 3D URP
This error significantly impacts development workflow automation and requires manual intervention for every custom component assignment.
This should be fixed in latest version. Please give a try and let us know.