//! This example illustrates loading scenes from files. use bevy::{prelude::*, tasks::IoTaskPool, utils::Duration}; use std::{fs::File, io::Write}; fn main() { App::new() .add_plugins(DefaultPlugins) .register_type::() .register_type::() .register_type::() .add_systems( Startup, (save_scene_system, load_scene_system, infotext_system), ) .add_systems(Update, log_system) .run(); } // Registered components must implement the `Reflect` and `FromWorld` traits. // The `Reflect` trait enables serialization, deserialization, and dynamic property access. // `Reflect` enable a bunch of cool behaviors, so its worth checking out the dedicated `reflect.rs` // example. The `FromWorld` trait determines how your component is constructed when it loads. // For simple use cases you can just implement the `Default` trait (which automatically implements // `FromWorld`). The simplest registered component just needs these three derives: #[derive(Component, Reflect, Default)] #[reflect(Component)] // this tells the reflect derive to also reflect component behaviors struct ComponentA { pub x: f32, pub y: f32, } // Some components have fields that cannot (or should not) be written to scene files. These can be // ignored with the #[reflect(skip_serializing)] attribute. This is also generally where the `FromWorld` // trait comes into play. `FromWorld` gives you access to your App's current ECS `Resources` // when you construct your component. #[derive(Component, Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(skip_serializing)] pub _time_since_startup: Duration, } impl FromWorld for ComponentB { fn from_world(world: &mut World) -> Self { let time = world.resource::