Skip to content

Keep serialized SceneIds saved before SceneId became a field - #1097

Open
jimdroberts wants to merge 1 commit into
FirstGearGames:mainfrom
jimdroberts:fix/sceneid-formerly-serialized
Open

jimdroberts wants to merge 1 commit into
FirstGearGames:mainfrom
jimdroberts:fix/sceneid-formerly-serialized

Conversation

@jimdroberts

Copy link
Copy Markdown
Contributor

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.cs L57-59. Up to 4.6.15 this was an auto-property:

[field: SerializeField]
[field: HideInInspector]
internal ulong SceneId { get; private set; }

Unity serializes it under the backing field's name, <SceneId>k__BackingField. 4.6.16R (caf94d2) made it a plain field, which Unity serializes as SceneId. 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 writes SceneId the 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+.

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.
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