Skip to content

Fix Unity 6000.6 InstanceIDToObjectCompat NotImplementedException - #1399

Open
yuseres wants to merge 1 commit into
CoplayDev:mainfrom
yuseres:fix/6000-6-instanceid-resolve
Open

Fix Unity 6000.6 InstanceIDToObjectCompat NotImplementedException#1399
yuseres wants to merge 1 commit into
CoplayDev:mainfrom
yuseres:fix/6000-6-instanceid-resolve

Conversation

@yuseres

@yuseres yuseres commented Sep 13, 2026

Copy link
Copy Markdown

Summary

Fixes #1398.

On Unity 6000.6.0f1, UnityObjectIdCompat.InstanceIDToObjectCompat(int) throws NotImplementedException for every call. This breaks manage_components (set_property/add) whenever GameObjectLookup resolves a target — including search_method="by_name", since FindByTarget round-trips through an instance ID internally — and breaks the gameobject/{id} and gameobject/{id}/components resources entirely.

Root cause

Verified via reflection against a live 6000.6.0f1 Editor: both EditorUtility.InstanceIDToObject(int) and EntityId's implicit int→EntityId conversion are unimplemented stubs at runtime on 6000.6.0f1 — not merely obsolete-marked. The existing CS0619-avoidance reflection shim successfully resolves the MethodInfo, but invoking it always throws.

The only reverse-resolution path that actually works on 6000.6 is:

EditorUtility.EntityIdToObject(EntityId.FromULong(fullUlong))

...which needs the full 64-bit id. GetInstanceIDCompat (forward direction) already discards the high 32 bits by truncating to int for wire compatibility, so by the time InstanceIDToObjectCompat receives the int, there's no way to reconstruct a valid EntityId from it alone.

Fix

Cache the full 64-bit value behind the truncated int at mint time (in GetInstanceIDCompat), and use that cache to resolve in InstanceIDToObjectCompat instead of trying to rebuild the EntityId from the int. This:

  • Keeps the existing int wire format and the already-documented session-scoped id contract (a static Dictionary naturally resets on domain reload, matching that scope)
  • Requires no changes to the ~30 call sites across the package or to the Python-side protocol
  • Only touches UnityObjectIdCompat.cs

Testing

Verified end-to-end against a live Unity 6000.6.0f1 project:

  • manage_components set_property targeting a GameObject by name (previously threw TargetInvocationExceptionNotImplementedException) — now succeeds
  • manage_components set_property targeting by a cross-call instance ID (obtained from an earlier find_gameobjects call) — now succeeds and actually writes the value
  • mcpforunity://scene/gameobject/{id}/components resource read — now returns data instead of erroring
  • No new console errors after the fix; clean recompile

🤖 Generated with Claude Code

On Unity 6000.6.0f1, both EditorUtility.InstanceIDToObject(int) and
EntityId's implicit int->EntityId conversion are unimplemented stubs at
runtime (verified via reflection against a live 6000.6.0f1 Editor) even
though the CS0619-avoidance reflection shim resolves the MethodInfo
successfully. Every call into InstanceIDToObjectCompat therefore threw
NotImplementedException, breaking manage_components (set_property/add)
whenever GameObjectLookup resolved a target - including by_name lookups,
since FindByTarget round-trips through an instance ID internally - and
breaking the gameobject/{id} and gameobject/{id}/components resources.

The only reverse-resolution path that works on 6000.6 is
EditorUtility.EntityIdToObject(EntityId.FromULong(fullUlong)), which
needs the full 64-bit id. GetInstanceIDCompat already discards the high
32 bits by truncating to int for wire compatibility, so by the time
InstanceIDToObjectCompat receives the int there's no way to reconstruct
a valid EntityId from it alone.

Cache the full 64-bit value behind the truncated int at mint time and
use that cache to resolve instead of trying to rebuild the EntityId
from the int. This keeps the existing int wire format and the
already-documented session-scoped id contract, with no changes needed
to any of the ~30 call sites or the wire protocol.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1541a0c4-144d-40e3-997e-6e641e15f1a5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants