Skip to content

Migrate instance-ID APIs to EntityId (6000.3+), widen handles to long#55

Merged
Niaobu merged 2 commits into
mainfrom
fix/entityid-instanceid-migration
Jun 22, 2026
Merged

Migrate instance-ID APIs to EntityId (6000.3+), widen handles to long#55
Niaobu merged 2 commits into
mainfrom
fix/entityid-instanceid-migration

Conversation

@Niaobu

@Niaobu Niaobu commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Supersedes #54 (builds on @bradar93's commit, included here with original authorship). Closes #54.

Problem

Unity deprecates the int-based instance-ID APIs (Object.GetInstanceID(), EditorUtility.InstanceIDToObject(int)) — a warning (CS0618) from 6000.3, obsolete-as-error (CS0619) from 6000.5. The package emitted these warnings on 6.3 and would fail to compile on 6.5.

Fix

Adopt the EntityId APIs behind a version gate, surfacing handles as long end-to-end.

Gate at 6000.3, not 6000.5 — the int APIs are already deprecated there and EntityId exists, so 6.3/6.4 stop warning. The API shape differs by version (verified by reflecting UnityEngine.EntityId in a live 6000.3.15f1 editor), so three regimes:

  • 6000.5+: EntityId is 64-bit — round-trip via EntityId.ToULong/FromULong.
  • 6000.3 / 6000.4: EntityId is int-backed — implicit EntityId ↔ int. (No ToULong/FromULong here — those are 6.5-only; the original Fix Unity 6000.5 compatibility: migrate InstanceID APIs to EntityId #54 single-path approach would not compile on 6.3.)
  • pre-6000.3: legacy GetInstanceID() / InstanceIDToObject(int).

Handles widened to long so a 6000.5 64-bit EntityId is never truncated; narrower ids widen and narrow back exactly:

  • Protocol DTOs: InstanceId, OpenedFromInstanceId, BlockedBy
  • CLI: --id options (snapshot, ui click), ParseInstanceIds + eval preamble
  • Package: wrappers, GetLongArgument, targetId/context paths, local StageInfo
  • Rebuilt the bundled UnityCtl.Protocol.dll

Testing

  • dotnet build clean · dotnet test 482 passed / 0 skipped (+2 tests for ids beyond int range)
  • On 6000.3.15f1: compiles clean (no Safe Mode), CS0618 deprecation warnings gone, snapshot --id round-trips at runtime (positive, negative, and >int32 ids all parse and resolve)
  • Note: the 6000.5 branch is verified to compile per Fix Unity 6000.5 compatibility: migrate InstanceID APIs to EntityId #54; not re-runnable here (this machine is on 6.3)

Abhi and others added 2 commits June 22, 2026 10:40
Unity 6000.5 renamed the int-based instance ID APIs to the 64-bit
EntityId type and marked Object.GetInstanceID() and
EditorUtility.InstanceIDToObject(int) obsolete-as-error (CS0619).

Add version-gated wrappers (GetObjectInstanceId / ResolveObjectById)
that use the new EntityId APIs on Unity 6000.5+ and fall back to the
legacy APIs on older versions (package still targets Unity 2022.3+).
Instance-ID handles remain int across the protocol; on 6000.5+ they
round-trip through EntityId.ToULong()/FromULong().

Also route the CLI's generated eval --id preamble through the new
ResolveObjectById helper so it compiles under Unity 6000.5.
@
Widen instance-id handles to long; adopt EntityId from 6000.3

Builds on the 6000.5 EntityId migration. Moves the #if gate to 6000.3,
where the int-based instance-ID APIs are already deprecated (CS0618) and
EntityId exists, so 6.3/6.4 stop emitting deprecation warnings. Uses a
three-way path because EntityId is int-backed on 6000.3/.4 (implicit
int conversions) and only 64-bit (ToULong/FromULong) on 6000.5+.

Surfaces handles as long end-to-end so a 6000.5 64-bit EntityId is never
truncated; narrower ids widen and narrow back exactly:
- Protocol DTOs: InstanceId, OpenedFromInstanceId, BlockedBy
- CLI: --id options (snapshot, ui click), ParseInstanceIds + eval preamble
- Package: wrappers, GetLongArgument, targetId/context paths, StageInfo
- Rebuilt bundled UnityCtl.Protocol.dll

Verified on 6000.3.15f1: compiles clean (no Safe Mode), deprecation
warnings gone, snapshot --id round-trips. dotnet build + 482 tests pass.
@
@Niaobu Niaobu merged commit 869b9a8 into main Jun 22, 2026
1 check passed
@Niaobu Niaobu deleted the fix/entityid-instanceid-migration branch June 22, 2026 08:52
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.

1 participant