Repository navigation
Keep serialized SceneIds saved before SceneId became a field - #1097
Open
jimdroberts wants to merge 1 commit into
Open
jimdroberts wants to merge 1 commit into
jimdroberts wants to merge 1 commit into
Conversation
4.6.16 changed NetworkObject.SceneId from an auto-property to a field. Unity had serialized the property's backing field as <SceneId>k__BackingField, and the field is serialized as SceneId, so every scene object and prefab saved with 4.6.15 or earlier loads with SceneId 0 after upgrading. Scene objects then get new ids or fail the missing-SceneId check in builds. Read the old name with FormerlySerializedAs.
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.
Problem
Upgrading from 4.6.15 or earlier to 4.6.16 or later silently resets the SceneId of every scene NetworkObject and every prefab that has one. Scenes then regenerate ids the next time they are opened in the editor (marking them dirty). A build made before that throws "is missing a SceneId", and scenes loaded from Addressables or AssetBundles can ship with unset ids. Found while upgrading a production project from 4.6.12: 36 serialized SceneIds across 20 scenes and prefabs.
Cause
Runtime/Object/NetworkObject/NetworkObject.Serialized.csL57-59. Up to 4.6.15 this was an auto-property:Unity serializes it under the backing field's name,
<SceneId>k__BackingField. 4.6.16R (caf94d2) made it a plain field, which Unity serializes asSceneId. No[FormerlySerializedAs]maps the old name, so the stored values are ignored and SceneId reads as 0.Fix
Add
[FormerlySerializedAs("<SceneId>k__BackingField")]to the field. Unity reads the old key once and writesSceneIdthe next time the asset is saved. Assets already saved with the new name are unaffected.Evidence
Verified by reading: the 4.6.12 YAML of every scene NetworkObject in the project above contains
<SceneId>k__BackingField: <id>, the 4.7.3R source declares a plain field, and nothing else in FishNet reads the old key. Compiled against Unity 6000.4 with no new errors or warnings.Behavior change
Projects upgrading from 4.6.15 or earlier keep their scene object ids. No change for projects already re-saved on 4.6.16+.