Add scene component snapshots#333
Merged
Merged
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.
Objective
Introduce a snapshot-based serialization workflow for scenes and components. The primary goal is to allow resource-backed (especially asset-backed) components to serialize stable references instead of transient runtime handles, enabling scenes to be saved and restored across worlds while preserving asset relationships.
This introduces
HandleSnapshot, component snapshot APIs, and TypeRegistry-driven snapshot restoration.Secondary changes include a small abstraction utility for snapshot interfaces and reusable abstract class error helpers.
Solution
Handle snapshots
Asset handles are runtime objects whose underlying IDs are not stable across scene serialization. To address this,
Handlenow supports conversion into a serializable snapshot,HandleSnapshot<T>.When an asset was loaded through the
AssetServer, the snapshot stores asset type, and asset path or it falls back to the asset id. Snapshots can later be used to restore a live handle. Path-backed assets are reloaded through the asset server while asset id snapshots upgrade against the registered asset pool.Note
Asset path snapshots are preferred because they survive world recreation. Asset ID snapshots remain supported as a fallback but restoration is currently limited and may become invalid when asset collections diverge between scene and world state.
Scene serialization pipeline
Scenes previously relied exclusively on registered
clone()methods. This worked for runtime duplication but could not correctly serialize resource-backed references. Scene serialization now supports dedicated snapshot methods. This allows components to serialize external references differently from runtime cloning behavior.Snapshot-enabled asset components
Added snapshot support for:
AudioPlayerMeshedBasicMaterial2DBasicMaterial3DSceneInstanceHandleEach component now converts asset handles into
HandleSnapshotinstances during scene serialization and restores them during scene spawning.:TypeRegistry integration
New snapshot types are registered in reflection metadata:
HandleSnapshotAudioPlayerSnapshotMeshedSnapshotBasicMaterial2DSnapshotBasicMaterial3DSnapshotSceneInstanceSnapshotThe registry now stores snapshot conversion methods allowing scene serialization to remain entirely reflection-driven.
Utility improvements
Added:
for indexed string formatting.
Added:
for reusable abstract-class and abstract-method validation.
Showcase
Example:
Register snapshot methods in the
TypeRegistry:Scenes cloned runtime handles directly. Asset-backed components depended on runtime asset IDs remaining valid. Now, components can serialize stable asset references to scenes. On spawning, snapshot is reloaded through the asset server to yield a correct handle.
Migration guide
No migration required
Checklist