Fix Unity 6000.6 InstanceIDToObjectCompat NotImplementedException - #1399
Open
yuseres wants to merge 1 commit into
Open
Fix Unity 6000.6 InstanceIDToObjectCompat NotImplementedException#1399yuseres wants to merge 1 commit into
yuseres wants to merge 1 commit into
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 <noreply@anthropic.com>
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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