Skip to content

fix: Unity 6.5 Scene.handle migration (int to ulong) with old version#1052

Open
JulianMKhoo wants to merge 3 commits into
FirstGearGames:mainfrom
JulianMKhoo:fix/unity6-scene
Open

fix: Unity 6.5 Scene.handle migration (int to ulong) with old version#1052
JulianMKhoo wants to merge 3 commits into
FirstGearGames:mainfrom
JulianMKhoo:fix/unity6-scene

Conversation

@JulianMKhoo

Copy link
Copy Markdown

Abstract

Unity 6000.5 changed Scene.handle from an int to an EntityId struct (raw value exposed via GetRawData()), and deprecated the EntityId / int implicit conversions. This broke FishNet scene loading/unloading, the scene comparers, and an observer-cleanup check. This PR migrates the scened code to the new type while keeping Unity 6.0 (and earlier 6.x) compiling.

Tested without errors on Unity 6000.5 and Unity 6000.0.

Report

Scene handle: int to ulong

  • Widened scene-handle storage from int to ulong across the scened API: SceneLookupData, SceneLoadData, SceneUnloadData, UnloadedScene, SceneManager pending-load maps, GetScene(...), etc.
  • Added a single Scene.GetHandleId() extension (SceneHandleExtensions) that isolates the only version-specific code:
    • UNITY_6000_5_OR_NEWER uses scene.handle.GetRawData()
    • older uses (ulong)(uint)scene.handle
  • All handle-read sites route through this helper, so no #if is scattered across the codebase and no public type flips per Unity version.
  • SceneComparer.GetHashCode now returns obj.handle.GetHashCode() (works on both int and the EntityId struct).

NetworkObserver condition cleanup

  • On UNITY_6000_5_OR_NEWER, use item.GetEntityId().IsValid() instead of GetInstanceID() < 0.
    • GetInstanceID()/< 0 route through the now-obsolete EntityId /int conversion, and a ulong-based < 0 is always false. so the old sign trick would silently never destroy.
    • Conditions in this list are always Instantiate()'d clones (see Initialize), so IsValid() destroys exactly the clones and never a source asset.
  • Older Unity uses GetInstanceID() < 0.

Minor

  • Refined Dictionaries.cs (TryGetValueIL2CPP).

Conclusion

  • Scene handle is only ever used as a dictionary key / equality token, so the exact inttoulong encoding on older Unity doesn't matter as long as it's consistent.
  • Please confirm UNITY_6000_5_OR_NEWER is the correct boundary (i.e. GetRawData() / the EntityId migration did not land before 6000.5).

@JulianMKhoo JulianMKhoo changed the title fix: Unity 6000.5 Scene.handle migration (int→ulong) with 6.0 backward compat fix: Unity 6.5 Scene.handle migration (int to ulong) with old version Jun 25, 2026
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