Closed
Description
Bevy version
0.11.3
[Optional] Relevant system information
AdapterInfo { name: "AMD JUNIPER (DRM 2.50.0 / 6.5.6-arch2-1, LLVM 16.0.6)", vendor: 65541, device: 0, device_type: Other, driver: "", driver_info: "", backend: Gl }
What you did
i saved and loaded a camerabundle2d :
use bevy::prelude::*;
use std::fs::File;
use bevy::tasks::IoTaskPool;
use std::io::Write;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup_save) // run once to generate save then comment and uncomment the line below to load
//.add_systems(Startup, setup_load)
.add_systems(Update, save)
.add_systems(Update, load)
.run();
}
#[derive(Component,Reflect,Default)]
pub struct Load;
#[derive(Component,Reflect)]
pub struct Save(Entity);
fn setup_save(
mut commands : Commands
){
let ent = commands.spawn(Camera2dBundle::default()).id();
commands.spawn(Save(ent));
println!("setup");
}
fn setup_load(
mut commands : Commands
){
commands.spawn(Load);
println!("setup load");
}
fn save(
world: &World,
query : Query<(&Save)>,
mut commands : Commands
) {
for s in query.iter(){
let savegame_save_path : &str = "assets/savegame.scn.ron";
let mut entity_array = vec![s.0];
let mut scene_builder = DynamicSceneBuilder::from_world(world);
scene_builder.allow_all();
scene_builder.deny::<ComputedVisibility>();// cant currently serialize with ComputedVisibilityFlags
scene_builder.extract_entities(entity_array.into_iter());
let scene = scene_builder.build();
let type_registry = world.resource::<AppTypeRegistry>().clone();
let serialized_scene = scene.serialize_ron(&type_registry).unwrap();
#[cfg(not(target_arch = "wasm32"))]
IoTaskPool::get()
.spawn(async move {
File::create(savegame_save_path)
.and_then(|mut file| file.write(serialized_scene.as_bytes()))
.expect("Error while writing scene to file");
})
.detach();
println!("save");
commands.entity(s.0).despawn_recursive();
}
}
fn load(
loaded_query : Query<&Load>,
mut commands : Commands,
asset_server: Res<AssetServer>,
) {
for i in loaded_query.iter(){
println!("load");
let save_path : &str = "savegame.scn.ron";
let scenehandle = asset_server.load(save_path);
commands.spawn(DynamicSceneBundle {
scene: scenehandle,
..default()
});
}
}
What went wrong
it wont load instead it will print an error like this:
WARN bevy_asset::asset_server: encountered an error while loading an asset: Expected float at savegame.scn.ron:25:15
which points to : x: -640.0,