Repository navigation
Fix Unity 6000.6 InstanceIDToObjectCompat NotImplementedException - #1399
Conversation
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 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Hi, can you rebase it to beta instead of main? |
This replaces the reflection-based
|
Summary
Fixes #1398.
On Unity 6000.6.0f1,
UnityObjectIdCompat.InstanceIDToObjectCompat(int)throwsNotImplementedExceptionfor every call. This breaksmanage_components(set_property/add) wheneverGameObjectLookupresolves a target — includingsearch_method="by_name", sinceFindByTargetround-trips through an instance ID internally — and breaks thegameobject/{id}andgameobject/{id}/componentsresources entirely.Root cause
Verified via reflection against a live 6000.6.0f1 Editor: both
EditorUtility.InstanceIDToObject(int)andEntityId's implicitint→EntityIdconversion are unimplemented stubs at runtime on 6000.6.0f1 — not merely obsolete-marked. The existing CS0619-avoidance reflection shim successfully resolves theMethodInfo, but invoking it always throws.The only reverse-resolution path that actually works on 6000.6 is:
...which needs the full 64-bit id.
GetInstanceIDCompat(forward direction) already discards the high 32 bits by truncating tointfor wire compatibility, so by the timeInstanceIDToObjectCompatreceives theint, there's no way to reconstruct a validEntityIdfrom it alone.Fix
Cache the full 64-bit value behind the truncated int at mint time (in
GetInstanceIDCompat), and use that cache to resolve inInstanceIDToObjectCompatinstead of trying to rebuild theEntityIdfrom the int. This:intwire format and the already-documented session-scoped id contract (a staticDictionarynaturally resets on domain reload, matching that scope)UnityObjectIdCompat.csTesting
Verified end-to-end against a live Unity 6000.6.0f1 project:
manage_components set_propertytargeting a GameObject by name (previously threwTargetInvocationException→NotImplementedException) — now succeedsmanage_components set_propertytargeting by a cross-call instance ID (obtained from an earlierfind_gameobjectscall) — now succeeds and actually writes the valuemcpforunity://scene/gameobject/{id}/componentsresource read — now returns data instead of erroring🤖 Generated with Claude Code