#1412·unity-mcp

Unity 6000.6+: InstanceIDToObjectCompat throws NotImplementedException (EditorUtility.InstanceIDToObject gutted)

Author: oz2036Created Sep 26, 2026Updated Sep 26, 2026

Environment

  • Unity: 6000.6.2f1 (Windows Editor)
  • MCP for Unity (com.coplaydev.unity-mcp): v10.2.0, tracking main (resolved commit 045e809812a8)

What happened

Reading GameObject-related MCP resources (mcpforunity://scene/gameobject/{id} and .../components) throws immediately:

[GameObjectResource] Error getting GameObject: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotImplementedException: The method or operation is not implemented.
  at UnityEditor.EditorUtility.InstanceIDToObject (System.Int32 instanceID)
  at MCPForUnity.Runtime.Helpers.UnityObjectIdCompat.InstanceIDToObjectCompat (System.Int32 instanceId) in Runtime/Helpers/UnityObjectIdCompat.cs:66
  at MCPForUnity.Editor.Helpers.GameObjectLookup.ResolveInstanceID (System.Int32 instanceId) in Editor/Helpers/GameObjectLookup.cs:73
  at MCPForUnity.Editor.Resources.Scene.GameObjectResource.HandleCommand (...) in Editor/Resources/Scene/GameObjectResource.cs:48

Root cause (as far as I can tell)

In Runtime/Helpers/UnityObjectIdCompat.cs, the UNITY_6000_6_OR_NEWER branch of InstanceIDToObjectCompat resolves EditorUtility.InstanceIDToObject(int) via reflection and invokes it:

csharp
#if UNITY_6000_6_OR_NEWER
    if (!_instanceIdToObjectInitialized) {
        _instanceIdToObject = typeof(EditorUtility).GetMethod(
            "InstanceIDToObject",
            BindingFlags.Public | BindingFlags.Static,
            null, new[] { typeof(int) }, null);
        _instanceIdToObjectInitialized = true;
    }
    return _instanceIdToObject?.Invoke(null, new object[] { instanceId }) as Object;

On Unity 6000.6.2f1, EditorUtility.InstanceIDToObject(int) still exists (so the reflection lookup succeeds) but its body now throws NotImplementedException at runtime — the method appears to have been gutted in favor of the new EntityId-based APIs. So every call into this compat shim fails on 6000.6+.

Repro

  1. Open a Unity 6000.6.2f1 project with MCP for Unity installed.
  2. From an MCP client, request mcpforunity://scene/gameobject/{instanceId} (or {instanceId}/components) for any valid instance ID in the open scene.
  3. Observe the console error above; the resource call returns "Error getting GameObject: Exception has been thrown by the target of an invocation.".

Impact

  • Doesn't affect the Unity project/game itself — only MCP tool calls that resolve a GameObject by instance ID fail.
  • Workaround I used: query the scene via SceneManager.GetActiveScene().GetRootGameObjects() / GetComponentsInChildren through execute_code instead of the gameobject/{id} resource.

Suggested fix

On 6000.6+, prefer an API that's actually implemented — e.g. resolving via GlobalObjectId round-trip, or whatever the new EntityId-based lookup is meant to be (EditorUtility.EntityIdToObject on 6000.3–6000.5 was used per the comment above this block; if that method (or an equivalent) still works on 6000.6, it may just need updating instead of falling back to the obsolete reflection call).