use bevy::{prelude::*, reflect::TypeRegistry, utils::Duration}; /// This example illustrates loading and saving scenes from files fn main() { App::build() .add_plugins(DefaultPlugins) .register_type::() .register_type::() .add_startup_system(save_scene_system.exclusive_system()) .add_startup_system(load_scene_system.system()) .add_startup_system(infotext_system.system()) .add_system(print_system.system()) .run(); } // Registered components must implement the `Reflect` and `FromResources` 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 `FromResources` trait determines how your component is constructed when it loads. For simple use cases you can just // implement the `Default` trait (which automatically implements FromResources). The simplest registered component just needs // these two derives: #[derive(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(ignore)] attribute. This is also generally where the `FromResources` trait comes into play. // `FromResources` gives you access to your App's current ECS `Resources` when you construct your component. #[derive(Reflect)] #[reflect(Component)] struct ComponentB { pub value: String, #[reflect(ignore)] pub time_since_startup: Duration, } impl FromResources for ComponentB { fn from_resources(resources: &Resources) -> Self { let time = resources.get::