There is bevy save: https://github.com/hankjordan/bevy_save which is not updated to 0.17. Was wondering if there were any alternatives beyond that
#Does bevy have any library for creating save states and load states?
6 messages · Page 1 of 1 (latest)
Bevy has saving features https://docs.rs/bevy/latest/bevy/scene/
https://taintedcoders.com/bevy/scenes
https://github.com/bevyengine/bevy/blob/main/examples/scene/scene.rs
Provides scene definition, instantiation and serialization/deserialization.
Tainted Coders
Scenes use reflection to serialize and deserialize components and entities into our game World. This guide will teach you everything you need to know about how scenes work in Bevy.
can you please show how to query entities from another function the example doesn't show that
I don't think I understand exaclty what you mean. I do this to write my entities with Tower and Spline to a file
pub fn save_level(
trigger: On<SaveLevel>,
towers: Query<Entity, With<Tower>>,
splines: Query<Entity, With<Spline>>,
world: DeferredWorld,
) {
// Filtering scene
let scene = DynamicSceneBuilder::from_world(&world)
.deny_all()
.allow_component::<Tower>()
.allow_component::<Transform>()
.allow_component::<Spline>()
.extract_resources()
.extract_entities(towers.iter())
.extract_entities(splines.iter())
.build();
// Type registry handling
let type_registry = world.resource::<AppTypeRegistry>();
let type_registry = type_registry.read();
let serialized_scene = scene.serialize(&type_registry).unwrap();
debug!("Saving scene: {}", serialized_scene);
// Writing to file
let filename = format!("assets/{0}", trigger.path);
IoTaskPool::get()
.spawn(async move {
// Write the scene RON data to file
File::create(filename)
.and_then(|mut file| file.write(serialized_scene.as_bytes()))
.expect("Error while writing scene to file");
})
.detach();
}
How to save an Sprite to a file?
How to pub fn save_level(
trigger: On<SaveLevel>,
towers: Query<Entity, With<Sprite >>,
world: DeferredWorld,
) {
// Filtering scene
let scene = DynamicSceneBuilder::from_world(&world)
.deny_all()
.allow_component::<Transform>()
.allow_component::<Sprite >()
.extract_resources()
.extract_entities(towers.iter())
.extract_entities(splines.iter())
.build();