Skip to content

First class save / load support #1442

Open
@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

Saving and loading game state is a core functionality that will be reused across almost every game made in Bevy, but implementing this functionality requires advanced Bevy knowledge and there isn't consensus on how you might effectively accomplish it.

What solution would you like?

A pair of Commands to save and load a game state, probably in combination with some Resources to set global config of this functionality.

@TheRawMeatball whipped up the following prototype:

struct SaveCommand;
struct LastSaveData(Option<SomeSerializedDataType>)
trait SaveCommandExt {
  fn save(&mut self);
}

impl Command for SaveCommand {
  fn write(self: Box<Self>, world: &mut World, resources: &mut Resources){
    let data = /*serialize stuff*/;
    resources.get_mut::<LastSaveData>().unwrap().0 = Some(data);
  }  
}

impl SaveCommandExt for Commands {
  fn save(&mut self) {
    self.add_command(SaveCommand)
  } 
}

Usage:

fn regular_system(commands: &mut Commands) {
  commands.save();
}

What alternative(s) have you considered?

Clearly document an idiomatic way to do this.

Additional context

Here's an example of a new user trying to implement this on their own and stumbling.

This issue relates directly to #255.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-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