Skip to content

Use scenes to serialize and deserialize resources #3576

@alice-i-cecile

Description

@alice-i-cecile

Problem

Serializing and deserializing resources is a common and important task. Currently, this must be done manually.

However, we already have a tool for this serialization: Scenes. Each Scene stores a World, which (now) includes resources, but the rest of the machinery is missing.

Proposed solution

Update the Scene machinery to handle resources as well. This should be reasonably straightforward (we can reflect resources, and we get access to the whole world when loading / saving / storing scenes), but fleshing out the rest of the API will be a fair bit of work.

The hardest part will be updating the serde .ron format: this presumes that only entities are included.

Our scene example should also be updated to show how to serialize / deserialize resources.

Alternatives considered

We could make a distinct serialization strategy for resources. This makes sense to include as part of scenes because:

  1. Common uses of scenes (saving / loading games, grabbing scenes from editors, networking) often include critical resources (current score, global illumination settings, difficulty settings) that should be logically batched together.
  2. Refactoring between entities and resources is very common, and two seperate strategies would cause frustrating refactoring pain.
  3. We're already storing a World everywhere for scenes.

Context

Before #1144, the World only stored entities and components. This code hasn't been updated to work for resources too yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ScenesSerialized ECS data stored on the diskC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions