| Crates.io | bevy_persist |
| lib.rs | bevy_persist |
| version | 0.1.0 |
| created_at | 2025-09-04 20:02:00.08228+00 |
| updated_at | 2025-09-04 20:02:00.08228+00 |
| description | Automatic persistence for Bevy resources with change detection |
| homepage | https://github.com/Alex-Gilbert/bevy_persist |
| repository | https://github.com/Alex-Gilbert/bevy_persist |
| max_upload_size | |
| id | 1824710 |
| size | 139,289 |
Automatic persistence for Bevy resources with change detection.
#[derive(Persist)] to make any resource persistentAdd to your Cargo.toml:
[dependencies]
bevy_persist = "0.1.0"
use bevy::prelude::*;
use bevy_persist::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Resource, Default, Serialize, Deserialize, Persist)]
struct Settings {
volume: f32,
difficulty: String,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(PersistPlugin)
.init_resource::<Settings>()
.run();
}
#[derive(Resource, Serialize, Deserialize, Persist)]
#[persist(auto_save = false)]
struct GraphicsSettings {
resolution: (u32, u32),
fullscreen: bool,
}
// Manual save in a system
fn save_graphics(
mut manager: ResMut<PersistManager>,
settings: Res<GraphicsSettings>,
) {
if settings.is_changed() {
let data = settings.to_persist_data();
manager.get_persist_file_mut()
.set_type_data("GraphicsSettings".to_string(), data);
manager.save().expect("Failed to save");
}
}
Use RON format for more readable configuration files:
App::new()
.add_plugins(PersistPlugin::new("settings.ron"))
// ...
Check out the examples/ directory for more usage examples:
basic.rs - Simple settings persistenceadvanced.rs - Complex game state with multiple persistent resourcesRun examples with:
cargo run --example basic
cargo run --example advanced
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.