#bevy-plugin #savegame #plugin #serialization #gamedev

bevy-where-was-i

A plugin for Bevy that saves and restores your camera position

2 releases

Uses new Rust 2024

new 0.1.1 Apr 12, 2025
0.1.0 Apr 12, 2025

#57 in #bevy-plugin

MIT license

27KB
331 lines

Bevy, where was I?

crate on crates.io docs on docs.rs build status

A tiny Bevy library that saves the camera position when the program closes, and restores it when you launch the application again. This is useful when debugging and you don't want to continuously change your hardcoded camera coordinates.

Note that this actually works for any Transform component, and not only restores translation information, but also scale and rotation.

This crate is compatible with bevy_panorbit_camera.

Usage

Add the plugin:

.add_plugins(WhereWasIPlugin::default())

For a camera

To save the translation and rotation of a camera, add the WhereWasI component to an entity with a Camera component:

commands.spawn((
    Camera::default(),
    WhereWasI::camera(),
));

Note: WhereWasI::camera() is equivalent to WhereWasI::from_name("camera").

For other entities

For other entities, a name has to be provided. Add the WhereWasI component to an entity with a Transform:

commands.spawn((
    PointLight::default(),
    WhereWasI::from_name("point_light"),
));

Since WhereWasI indicates that Transform is a required component, we can omit it and WhereWasI will construct it. If you want to change the initial state of the Transform before a savefile exists, add a Transform component to the bundle:

commands.spawn((
    PointLight::default(),
    Transform::from_xyz(5.0, 2.0, 5.0),
    WhereWasI::from_name("point_light"),
));

See the 3D scene example for a complete example.

Save files

The save files will by default be stored in ./assets/saves. You likely want to add this directory to you .gitignore. Alternatvely, you can configure a different directory when initializing the plugin. For example, you can store the savefiles in the user's .config directory:

.add_plugins(WhereWasIPlugin {
    directory: "~/.config/bevy-saves/my-game".into(),
})

WhereWasIPlugin will make sure the directory exists if it doesn't already.

License

Bracket is licensed under MIT, see LICENSE.

Dependencies

~25–36MB
~611K SLoC