fix: Unity 6.5 Scene.handle migration (int to ulong) with old version#1052
Open
JulianMKhoo wants to merge 3 commits into
Open
fix: Unity 6.5 Scene.handle migration (int to ulong) with old version#1052JulianMKhoo wants to merge 3 commits into
JulianMKhoo wants to merge 3 commits into
Conversation
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.
Abstract
Unity 6000.5 changed
Scene.handlefrom anintto anEntityIdstruct (raw value exposed viaGetRawData()), and deprecated theEntityId/intimplicit 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:
inttoulonginttoulongacross the scened API:SceneLookupData,SceneLoadData,SceneUnloadData,UnloadedScene,SceneManagerpending-load maps,GetScene(...), etc.Scene.GetHandleId()extension (SceneHandleExtensions) that isolates the only version-specific code:UNITY_6000_5_OR_NEWERusesscene.handle.GetRawData()(ulong)(uint)scene.handle#ifis scattered across the codebase and no public type flips per Unity version.SceneComparer.GetHashCodenow returnsobj.handle.GetHashCode()(works on bothintand theEntityIdstruct).NetworkObserver condition cleanup
UNITY_6000_5_OR_NEWER, useitem.GetEntityId().IsValid()instead ofGetInstanceID() < 0.GetInstanceID()/< 0route through the now-obsoleteEntityId/intconversion, and aulong-based< 0is always false. so the old sign trick would silently never destroy.Instantiate()'d clones (seeInitialize), soIsValid()destroys exactly the clones and never a source asset.GetInstanceID() < 0.Minor
Dictionaries.cs(TryGetValueIL2CPP).Conclusion
inttoulongencoding on older Unity doesn't matter as long as it's consistent.UNITY_6000_5_OR_NEWERis the correct boundary (i.e.GetRawData()/ theEntityIdmigration did not land before 6000.5).