diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index ee70d801ef952..ea3b5560ff571 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -17,7 +17,7 @@ use bevy_ecs::{ }; use bevy_hierarchy::Children; use bevy_math::{Quat, Vec3}; -use bevy_reflect::{Reflect, TypeUuid}; +use bevy_reflect::{FromReflect, Reflect, TypeUuid}; use bevy_time::Time; use bevy_transform::{prelude::Transform, TransformSystem}; use bevy_utils::{tracing::warn, HashMap}; @@ -91,7 +91,7 @@ impl AnimationClip { } /// Animation controls -#[derive(Component, Reflect)] +#[derive(Component, Reflect, FromReflect)] #[reflect(Component)] pub struct AnimationPlayer { paused: bool, diff --git a/crates/bevy_core/src/name.rs b/crates/bevy_core/src/name.rs index fe320300fd03d..042f89cb77d2f 100644 --- a/crates/bevy_core/src/name.rs +++ b/crates/bevy_core/src/name.rs @@ -1,6 +1,6 @@ use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use bevy_utils::AHasher; use std::{ borrow::Cow, @@ -14,7 +14,7 @@ use std::{ /// [`Name`] should not be treated as a globally unique identifier for entities, /// as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be /// used instead as the default unique identifier. -#[derive(Component, Debug, Clone, Reflect)] +#[derive(Component, Debug, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct Name { hash: u64, // TODO: Shouldn't be serialized diff --git a/crates/bevy_core_pipeline/src/clear_color.rs b/crates/bevy_core_pipeline/src/clear_color.rs index 6160f2256f039..c9e233ec2625c 100644 --- a/crates/bevy_core_pipeline/src/clear_color.rs +++ b/crates/bevy_core_pipeline/src/clear_color.rs @@ -1,10 +1,10 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::prelude::*; -use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_render::{color::Color, extract_resource::ExtractResource}; use serde::{Deserialize, Serialize}; -#[derive(Reflect, Serialize, Deserialize, Clone, Debug, Default)] +#[derive(Reflect, FromReflect, Serialize, Deserialize, Clone, Debug, Default)] #[reflect_value(Serialize, Deserialize)] pub enum ClearColorConfig { #[default] diff --git a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs index e389ca68331d7..228bc3711a316 100644 --- a/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs +++ b/crates/bevy_core_pipeline/src/core_2d/camera_2d.rs @@ -1,6 +1,6 @@ use crate::clear_color::ClearColorConfig; use bevy_ecs::{prelude::*, query::QueryItem}; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use bevy_render::{ camera::{ Camera, CameraProjection, CameraRenderGraph, DepthCalculation, OrthographicProjection, @@ -11,7 +11,7 @@ use bevy_render::{ }; use bevy_transform::prelude::{GlobalTransform, Transform}; -#[derive(Component, Default, Reflect, Clone)] +#[derive(Component, Default, Reflect, FromReflect, Clone)] #[reflect(Component)] pub struct Camera2d { pub clear_color: ClearColorConfig, diff --git a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs index bca403cc0303c..e328505b876d9 100644 --- a/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs +++ b/crates/bevy_core_pipeline/src/core_3d/camera_3d.rs @@ -1,6 +1,6 @@ use crate::clear_color::ClearColorConfig; use bevy_ecs::{prelude::*, query::QueryItem}; -use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_render::{ camera::{Camera, CameraRenderGraph, Projection}, extract_component::ExtractComponent, @@ -12,7 +12,7 @@ use bevy_transform::prelude::{GlobalTransform, Transform}; use serde::{Deserialize, Serialize}; /// Configuration for the "main 3d render graph". -#[derive(Component, Reflect, Clone, Default)] +#[derive(Component, Reflect, FromReflect, Clone, Default)] #[reflect(Component)] pub struct Camera3d { /// The clear color operation to perform for the main 3d pass. @@ -22,7 +22,7 @@ pub struct Camera3d { } /// The depth clear operation to perform for the main 3d pass. -#[derive(Reflect, Serialize, Deserialize, Clone, Debug)] +#[derive(Reflect, FromReflect, Serialize, Deserialize, Clone, Debug)] #[reflect_value(Serialize, Deserialize)] pub enum Camera3dDepthLoadOp { /// Clear with a specified value. diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index e022483fa836c..7ce5df58cb978 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -143,7 +143,8 @@ impl Entity { /// ```no_run /// # use bevy_ecs::{prelude::*, component::*}; /// # use bevy_reflect::Reflect; - /// #[derive(Reflect, Component)] + /// # use bevy_reflect::FromReflect; + /// #[derive(Reflect, FromReflect, Component)] /// #[reflect(Component)] /// pub struct MyStruct { /// pub entity: Entity, diff --git a/crates/bevy_ecs/src/reflect.rs b/crates/bevy_ecs/src/reflect.rs index 0b288b3aa7ac0..fe9bd74b6ea8e 100644 --- a/crates/bevy_ecs/src/reflect.rs +++ b/crates/bevy_ecs/src/reflect.rs @@ -1,6 +1,7 @@ //! Types that enable reflection support. pub use crate::change_detection::ReflectMut; +use crate::system::EntityCommands; use crate::{ component::Component, entity::{Entity, EntityMap, MapEntities, MapEntitiesError}, @@ -8,8 +9,8 @@ use crate::{ world::{FromWorld, World}, }; use bevy_reflect::{ - impl_from_reflect_value, impl_reflect_value, FromType, Reflect, ReflectDeserialize, - ReflectSerialize, + impl_from_reflect_value, impl_reflect_value, FromReflect, FromType, Reflect, + ReflectDeserialize, ReflectSerialize, }; /// A struct used to operate on reflected [`Component`] of a type. @@ -19,6 +20,7 @@ use bevy_reflect::{ #[derive(Clone)] pub struct ReflectComponent { insert: fn(&mut World, Entity, &dyn Reflect), + insert_command: fn(&mut EntityCommands, &dyn Reflect), apply: fn(&mut World, Entity, &dyn Reflect), apply_or_insert: fn(&mut World, Entity, &dyn Reflect), remove: fn(&mut World, Entity), @@ -32,16 +34,26 @@ impl ReflectComponent { /// /// # Panics /// - /// Panics if there is no such entity. + /// Panics if there is no such entity or if the concrete type's [`FromReflect::from_reflect()`] call fails. pub fn insert(&self, world: &mut World, entity: Entity, component: &dyn Reflect) { (self.insert)(world, entity, component); } + /// Insert a reflected [`Component`] into the entity like [`EntityCommands::insert()`]. + /// + /// # Panics + /// + /// Panics if the concrete type's [`FromReflect::from_reflect()`] call fails. + pub fn insert_command(&self, commands: &mut EntityCommands, component: &dyn Reflect) { + (self.insert_command)(commands, component); + } + /// Uses reflection to set the value of this [`Component`] type in the entity to the given value. /// /// # Panics /// - /// Panics if there is no [`Component`] of the given type or the `entity` does not exist. + /// Panics if there is no [`Component`] of the given type, if the `entity` does not exist, or if + /// the concrete type's [`FromReflect::from_reflect()`] call fails. pub fn apply(&self, world: &mut World, entity: Entity, component: &dyn Reflect) { (self.apply)(world, entity, component); } @@ -50,7 +62,7 @@ impl ReflectComponent { /// /// # Panics /// - /// Panics if the `entity` does not exist. + /// Panics if the `entity` does not exist, or if the component does not exist and the type's [`FromReflect::from_reflect()`] fails. pub fn apply_or_insert(&self, world: &mut World, entity: Entity, component: &dyn Reflect) { (self.apply_or_insert)(world, entity, component); } @@ -110,24 +122,31 @@ impl ReflectComponent { } } -impl FromType for ReflectComponent { +impl FromType for ReflectComponent { fn from_type() -> Self { ReflectComponent { insert: |world, entity, reflected_component| { - let mut component = C::from_world(world); - component.apply(reflected_component); + let component = C::from_reflect(reflected_component) + .expect("failed to call `FromReflect::from_reflect` on dynamic component"); world.entity_mut(entity).insert(component); }, + insert_command: |commands, reflected_component| { + let component = C::from_reflect(reflected_component) + .expect("failed to call `FromReflect::from_reflect` on dynamic component"); + commands.insert(component); + }, apply: |world, entity, reflected_component| { - let mut component = world.get_mut::(entity).unwrap(); + let mut component = world + .get_mut::(entity) + .expect("failed to get component on entity"); component.apply(reflected_component); }, apply_or_insert: |world, entity, reflected_component| { if let Some(mut component) = world.get_mut::(entity) { component.apply(reflected_component); } else { - let mut component = C::from_world(world); - component.apply(reflected_component); + let component = C::from_reflect(reflected_component) + .expect("failed to call `FromReflect::from_reflect` on dynamic component"); world.entity_mut(entity).insert(component); } }, @@ -135,9 +154,11 @@ impl FromType for ReflectComponent { world.entity_mut(entity).remove::(); }, copy: |source_world, destination_world, source_entity, destination_entity| { - let source_component = source_world.get::(source_entity).unwrap(); - let mut destination_component = C::from_world(destination_world); - destination_component.apply(source_component); + let source_component = source_world + .get::(source_entity) + .expect("failed to get component on source entity"); + let destination_component = C::from_reflect(source_component) + .expect("failed to call `FromReflect::from_reflect` on dynamic component"); destination_world .entity_mut(destination_entity) .insert(destination_component); diff --git a/crates/bevy_gltf/src/lib.rs b/crates/bevy_gltf/src/lib.rs index f86efd9732ffb..2bf48e0d08716 100644 --- a/crates/bevy_gltf/src/lib.rs +++ b/crates/bevy_gltf/src/lib.rs @@ -9,7 +9,7 @@ use bevy_app::prelude::*; use bevy_asset::{AddAsset, Handle}; use bevy_ecs::{prelude::Component, reflect::ReflectComponent}; use bevy_pbr::StandardMaterial; -use bevy_reflect::{Reflect, TypeUuid}; +use bevy_reflect::{FromReflect, Reflect, TypeUuid}; use bevy_render::mesh::Mesh; use bevy_scene::Scene; @@ -72,7 +72,7 @@ pub struct GltfPrimitive { pub material: Option>, } -#[derive(Clone, Debug, Reflect, Default, Component)] +#[derive(Clone, Debug, Reflect, FromReflect, Default, Component)] #[reflect(Component)] pub struct GltfExtras { pub value: String, diff --git a/crates/bevy_hierarchy/src/components/children.rs b/crates/bevy_hierarchy/src/components/children.rs index 68e453ee85985..4c720374e8b7b 100644 --- a/crates/bevy_hierarchy/src/components/children.rs +++ b/crates/bevy_hierarchy/src/components/children.rs @@ -5,13 +5,13 @@ use bevy_ecs::{ reflect::{ReflectComponent, ReflectMapEntities}, world::World, }; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use core::slice; use smallvec::SmallVec; use std::ops::Deref; /// Contains references to the child entities of this entity -#[derive(Component, Debug, Reflect)] +#[derive(Component, Debug, Reflect, FromReflect)] #[reflect(Component, MapEntities)] pub struct Children(pub(crate) SmallVec<[Entity; 8]>); diff --git a/crates/bevy_hierarchy/src/components/parent.rs b/crates/bevy_hierarchy/src/components/parent.rs index d4a5e2f3bec70..c10e36c1b6a8d 100644 --- a/crates/bevy_hierarchy/src/components/parent.rs +++ b/crates/bevy_hierarchy/src/components/parent.rs @@ -4,12 +4,12 @@ use bevy_ecs::{ reflect::{ReflectComponent, ReflectMapEntities}, world::{FromWorld, World}, }; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use std::ops::Deref; /// Holds a reference to the parent entity of this entity. /// This component should only be present on entities that actually have a parent entity. -#[derive(Component, Debug, Eq, PartialEq, Reflect)] +#[derive(Component, Debug, Eq, PartialEq, Reflect, FromReflect)] #[reflect(Component, MapEntities, PartialEq)] pub struct Parent(pub(crate) Entity); diff --git a/crates/bevy_pbr/src/alpha.rs b/crates/bevy_pbr/src/alpha.rs index 55f0a7ff9858d..003e0a6da0758 100644 --- a/crates/bevy_pbr/src/alpha.rs +++ b/crates/bevy_pbr/src/alpha.rs @@ -1,10 +1,10 @@ use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; // FIXME: This should probably be part of bevy_render2! /// Alpha mode -#[derive(Component, Debug, Default, Reflect, Copy, Clone, PartialEq)] +#[derive(Component, Debug, Default, Reflect, FromReflect, Copy, Clone, PartialEq)] #[reflect(Component, Default)] pub enum AlphaMode { #[default] diff --git a/crates/bevy_pbr/src/bundle.rs b/crates/bevy_pbr/src/bundle.rs index 0bd720d11ea06..6de58ff376138 100644 --- a/crates/bevy_pbr/src/bundle.rs +++ b/crates/bevy_pbr/src/bundle.rs @@ -1,7 +1,7 @@ use crate::{DirectionalLight, Material, PointLight, SpotLight, StandardMaterial}; use bevy_asset::Handle; use bevy_ecs::{bundle::Bundle, component::Component, reflect::ReflectComponent}; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use bevy_render::{ mesh::Mesh, primitives::{CubemapFrusta, Frustum}, @@ -38,7 +38,7 @@ impl Default for MaterialMeshBundle { } } -#[derive(Component, Clone, Debug, Default, Reflect)] +#[derive(Component, Clone, Debug, Default, Reflect, FromReflect)] #[reflect(Component)] pub struct CubemapVisibleEntities { #[reflect(ignore)] diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 5033b273b1b32..ecbce1ebdbdbb 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -3,6 +3,7 @@ use std::collections::HashSet; use bevy_ecs::prelude::*; use bevy_math::{Mat4, UVec2, UVec3, Vec2, Vec3, Vec3A, Vec3Swizzles, Vec4, Vec4Swizzles}; use bevy_reflect::prelude::*; +use bevy_reflect::FromReflect; use bevy_render::{ camera::{Camera, CameraProjection, OrthographicProjection}, color::Color, @@ -38,7 +39,7 @@ use crate::{ /// | 4000 | 300 | | 75-100 | 40.5 | /// /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) -#[derive(Component, Debug, Clone, Copy, Reflect)] +#[derive(Component, Debug, Clone, Copy, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct PointLight { pub color: Color, @@ -89,7 +90,7 @@ impl Default for PointLightShadowMap { /// Behaves like a point light in a perfectly absorbant housing that /// shines light only in a given direction. The direction is taken from /// the transform, and can be specified with [`Transform::looking_at`](bevy_transform::components::Transform::looking_at). -#[derive(Component, Debug, Clone, Copy, Reflect)] +#[derive(Component, Debug, Clone, Copy, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct SpotLight { pub color: Color, @@ -164,7 +165,7 @@ impl Default for SpotLight { /// | 32,000–100,000 | Direct sunlight | /// /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux) -#[derive(Component, Debug, Clone, Reflect)] +#[derive(Component, Debug, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct DirectionalLight { pub color: Color, @@ -239,11 +240,11 @@ impl Default for AmbientLight { } /// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. -#[derive(Component, Reflect, Default)] +#[derive(Component, Reflect, FromReflect, Default)] #[reflect(Component, Default)] pub struct NotShadowCaster; /// Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not receive shadows. -#[derive(Component, Reflect, Default)] +#[derive(Component, Reflect, FromReflect, Default)] #[reflect(Component, Default)] pub struct NotShadowReceiver; diff --git a/crates/bevy_pbr/src/wireframe.rs b/crates/bevy_pbr/src/wireframe.rs index b194fa5983e54..40a8dba24c22c 100644 --- a/crates/bevy_pbr/src/wireframe.rs +++ b/crates/bevy_pbr/src/wireframe.rs @@ -5,7 +5,7 @@ use bevy_asset::{load_internal_asset, Handle, HandleUntyped}; use bevy_core_pipeline::core_3d::Opaque3d; use bevy_ecs::{prelude::*, reflect::ReflectComponent}; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::{Reflect, TypeUuid}; +use bevy_reflect::{FromReflect, Reflect, TypeUuid}; use bevy_render::Extract; use bevy_render::{ extract_resource::{ExtractResource, ExtractResourcePlugin}, @@ -58,7 +58,7 @@ fn extract_wireframes(mut commands: Commands, query: Extract, } -#[derive(Component, Debug, Reflect, Clone)] +#[derive(Component, Debug, Reflect, FromReflect, Clone)] #[reflect(Component)] pub struct Camera { /// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`]. @@ -230,7 +231,7 @@ impl Camera { } /// Configures the [`RenderGraph`](crate::render_graph::RenderGraph) name assigned to be run for a given [`Camera`] entity. -#[derive(Component, Deref, DerefMut, Reflect, Default)] +#[derive(Component, Deref, DerefMut, Reflect, FromReflect, Default)] #[reflect(Component)] pub struct CameraRenderGraph(Cow<'static, str>); @@ -309,7 +310,7 @@ impl RenderTarget { } } -#[derive(Debug, Clone, Copy, Default, Reflect, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, Default, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Serialize, Deserialize)] pub enum DepthCalculation { /// Pythagorean distance; works everywhere, more expensive to compute. diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index aaf0e761bba37..c20f3f75cfca6 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -4,6 +4,7 @@ use super::DepthCalculation; use bevy_app::{App, CoreStage, Plugin, StartupStage}; use bevy_ecs::{prelude::*, reflect::ReflectComponent}; use bevy_math::Mat4; +use bevy_reflect::FromReflect; use bevy_reflect::{ std_traits::ReflectDefault, GetTypeRegistration, Reflect, ReflectDeserialize, ReflectSerialize, }; @@ -46,7 +47,7 @@ pub trait CameraProjection { } /// A configurable [`CameraProjection`] that can select its projection type at runtime. -#[derive(Component, Debug, Clone, Reflect)] +#[derive(Component, Debug, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub enum Projection { Perspective(PerspectiveProjection), @@ -101,7 +102,7 @@ impl Default for Projection { } } -#[derive(Component, Debug, Clone, Reflect)] +#[derive(Component, Debug, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct PerspectiveProjection { pub fov: f32, @@ -140,14 +141,14 @@ impl Default for PerspectiveProjection { } // TODO: make this a component instead of a property -#[derive(Debug, Clone, Reflect, Serialize, Deserialize)] +#[derive(Debug, Clone, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Serialize, Deserialize)] pub enum WindowOrigin { Center, BottomLeft, } -#[derive(Debug, Clone, Reflect, Serialize, Deserialize)] +#[derive(Debug, Clone, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Serialize, Deserialize)] pub enum ScalingMode { /// Manually specify left/right/top/bottom values. @@ -166,7 +167,7 @@ pub enum ScalingMode { FixedHorizontal(f32), } -#[derive(Component, Debug, Clone, Reflect)] +#[derive(Component, Debug, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct OrthographicProjection { pub left: f32, diff --git a/crates/bevy_render/src/mesh/mesh/skinning.rs b/crates/bevy_render/src/mesh/mesh/skinning.rs index 6d152689069ea..bcb77e88bb7dd 100644 --- a/crates/bevy_render/src/mesh/mesh/skinning.rs +++ b/crates/bevy_render/src/mesh/mesh/skinning.rs @@ -6,10 +6,10 @@ use bevy_ecs::{ reflect::ReflectMapEntities, }; use bevy_math::Mat4; -use bevy_reflect::{Reflect, TypeUuid}; +use bevy_reflect::{FromReflect, Reflect, TypeUuid}; use std::ops::Deref; -#[derive(Component, Debug, Default, Clone, Reflect)] +#[derive(Component, Debug, Default, Clone, Reflect, FromReflect)] #[reflect(Component, MapEntities)] pub struct SkinnedMesh { pub inverse_bindposes: Handle, diff --git a/crates/bevy_render/src/primitives/mod.rs b/crates/bevy_render/src/primitives/mod.rs index ae82c844be6ce..6a6f711721ab5 100644 --- a/crates/bevy_render/src/primitives/mod.rs +++ b/crates/bevy_render/src/primitives/mod.rs @@ -1,9 +1,9 @@ use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles}; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; /// An Axis-Aligned Bounding Box -#[derive(Component, Clone, Debug, Default, Reflect)] +#[derive(Component, Clone, Debug, Default, Reflect, FromReflect)] #[reflect(Component)] pub struct Aabb { pub center: Vec3A, @@ -126,7 +126,7 @@ impl Plane { /// A frustum defined by the 6 containing planes /// Planes are ordered left, right, top, bottom, near, far /// Normals point into the contained volume -#[derive(Component, Clone, Copy, Debug, Default, Reflect)] +#[derive(Component, Clone, Copy, Debug, Default, Reflect, FromReflect)] #[reflect(Component)] pub struct Frustum { #[reflect(ignore)] @@ -193,7 +193,7 @@ impl Frustum { } } -#[derive(Component, Debug, Default, Reflect)] +#[derive(Component, Debug, Default, Reflect, FromReflect)] #[reflect(Component)] pub struct CubemapFrusta { #[reflect(ignore)] diff --git a/crates/bevy_render/src/view/visibility/mod.rs b/crates/bevy_render/src/view/visibility/mod.rs index eb14f94f1ad2a..8e2d32b6947ab 100644 --- a/crates/bevy_render/src/view/visibility/mod.rs +++ b/crates/bevy_render/src/view/visibility/mod.rs @@ -7,7 +7,7 @@ use bevy_asset::{Assets, Handle}; use bevy_ecs::prelude::*; use bevy_hierarchy::{Children, Parent}; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use bevy_transform::components::GlobalTransform; use bevy_transform::TransformSystem; use std::cell::Cell; @@ -23,7 +23,7 @@ use crate::{ /// If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. /// This is done by setting the values of their [`ComputedVisibility`] component. -#[derive(Component, Clone, Reflect, Debug)] +#[derive(Component, Clone, Reflect, FromReflect, Debug)] #[reflect(Component, Default)] pub struct Visibility { /// Indicates whether this entity is visible. Hidden values will propagate down the entity hierarchy. @@ -46,7 +46,7 @@ impl Visibility { } /// Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering -#[derive(Component, Clone, Reflect, Debug, Eq, PartialEq)] +#[derive(Component, Clone, Reflect, FromReflect, Debug, Eq, PartialEq)] #[reflect(Component)] pub struct ComputedVisibility { is_visible_in_hierarchy: bool, @@ -139,7 +139,7 @@ pub struct NoFrustumCulling; /// /// Currently this component is ignored by the sprite renderer, so sprite rendering /// is not optimized per view. -#[derive(Clone, Component, Default, Debug, Reflect)] +#[derive(Clone, Component, Default, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct VisibleEntities { #[reflect(ignore)] diff --git a/crates/bevy_render/src/view/visibility/render_layers.rs b/crates/bevy_render/src/view/visibility/render_layers.rs index 677c0877777ba..855cbe6de5060 100644 --- a/crates/bevy_render/src/view/visibility/render_layers.rs +++ b/crates/bevy_render/src/view/visibility/render_layers.rs @@ -1,6 +1,6 @@ use bevy_ecs::prelude::{Component, ReflectComponent}; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; type LayerMask = u32; @@ -20,7 +20,7 @@ pub type Layer = u8; /// An entity with this component without any layers is invisible. /// /// Entities without this component belong to layer `0`. -#[derive(Component, Copy, Clone, Reflect, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Component, Copy, Clone, Reflect, FromReflect, PartialEq, Eq, PartialOrd, Ord)] #[reflect(Component, Default, PartialEq)] pub struct RenderLayers(LayerMask); diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 41188cd48679f..76330734021eb 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -5,7 +5,7 @@ use bevy_ecs::{ system::{lifetimeless::*, SystemParamItem, SystemState}, }; use bevy_math::{Mat4, Vec2}; -use bevy_reflect::{Reflect, TypeUuid}; +use bevy_reflect::{FromReflect, Reflect, TypeUuid}; use bevy_render::{ extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin}, mesh::{GpuBufferInfo, Mesh, MeshVertexBufferLayout}, @@ -24,7 +24,7 @@ use bevy_transform::components::GlobalTransform; /// Component for rendering with meshes in the 2d pipeline, usually with a [2d material](crate::Material2d) such as [`ColorMaterial`](crate::ColorMaterial). /// /// It wraps a [`Handle`] to differentiate from the 3d pipelines which use the handles directly as components -#[derive(Default, Clone, Component, Debug, Reflect)] +#[derive(Default, Clone, Component, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct Mesh2dHandle(pub Handle); diff --git a/crates/bevy_sprite/src/rect.rs b/crates/bevy_sprite/src/rect.rs index 3a7fb2a04dd26..7ac1a8cf3da65 100644 --- a/crates/bevy_sprite/src/rect.rs +++ b/crates/bevy_sprite/src/rect.rs @@ -1,10 +1,10 @@ use bevy_math::Vec2; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; /// A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere /// (top-left, bottom-left, etc) #[repr(C)] -#[derive(Default, Clone, Copy, Debug, Reflect)] +#[derive(Default, Clone, Copy, Debug, Reflect, FromReflect)] pub struct Rect { /// The beginning point of the rect pub min: Vec2, diff --git a/crates/bevy_text/src/text.rs b/crates/bevy_text/src/text.rs index b2440e1988aaa..891191b824e1b 100644 --- a/crates/bevy_text/src/text.rs +++ b/crates/bevy_text/src/text.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use crate::Font; -#[derive(Component, Debug, Default, Clone, Reflect)] +#[derive(Component, Debug, Default, Clone, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct Text { pub sections: Vec, @@ -117,7 +117,7 @@ impl TextSection { } } -#[derive(Debug, Clone, Copy, Reflect)] +#[derive(Debug, Clone, Copy, Reflect, FromReflect)] pub struct TextAlignment { pub vertical: VerticalAlign, pub horizontal: HorizontalAlign, @@ -186,7 +186,7 @@ impl Default for TextAlignment { } /// Describes horizontal alignment preference for positioning & bounds. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Serialize, Deserialize)] pub enum HorizontalAlign { /// Leftmost character is immediately to the right of the render position.
@@ -212,7 +212,7 @@ impl From for glyph_brush_layout::HorizontalAlign { /// Describes vertical alignment preference for positioning & bounds. Currently a placeholder /// for future functionality. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Serialize, Deserialize)] pub enum VerticalAlign { /// Characters/bounds start underneath the render position and progress downwards. diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index dd4a5b63f5a23..3c295861309de 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -9,7 +9,7 @@ use bevy_ecs::{ system::{Local, Query, Res, ResMut}, }; use bevy_math::{Vec2, Vec3}; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use bevy_render::{ prelude::Color, texture::Image, @@ -26,7 +26,7 @@ use crate::{ }; /// The calculated size of text drawn in 2D scene. -#[derive(Component, Default, Copy, Clone, Debug, Reflect)] +#[derive(Component, Default, Copy, Clone, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct Text2dSize { pub size: Vec2, @@ -39,7 +39,7 @@ pub struct Text2dSize { /// Note: only characters that are completely out of the bounds will be truncated, so this is not a /// reliable limit if it is necessary to contain the text strictly in the bounds. Currently this /// component is mainly useful for text wrapping only. -#[derive(Component, Copy, Clone, Debug, Reflect)] +#[derive(Component, Copy, Clone, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct Text2dBounds { pub size: Vec2, diff --git a/crates/bevy_transform/src/components/global_transform.rs b/crates/bevy_transform/src/components/global_transform.rs index f1129f8681116..3fe52bb4cf939 100644 --- a/crates/bevy_transform/src/components/global_transform.rs +++ b/crates/bevy_transform/src/components/global_transform.rs @@ -3,7 +3,7 @@ use std::ops::Mul; use super::Transform; use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Affine3A, Mat4, Quat, Vec3, Vec3A}; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; /// Describe the position of an entity relative to the reference frame. /// @@ -25,7 +25,7 @@ use bevy_reflect::Reflect; /// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you /// update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. -#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)] +#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect, FromReflect)] #[reflect(Component, PartialEq)] pub struct GlobalTransform(Affine3A); diff --git a/crates/bevy_transform/src/components/transform.rs b/crates/bevy_transform/src/components/transform.rs index e22a7df0cd173..357b16d87a2a8 100644 --- a/crates/bevy_transform/src/components/transform.rs +++ b/crates/bevy_transform/src/components/transform.rs @@ -2,7 +2,7 @@ use super::GlobalTransform; use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_math::{Affine3A, Mat3, Mat4, Quat, Vec3}; use bevy_reflect::prelude::*; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use std::ops::Mul; /// Describe the position of an entity. If the entity has a parent, the position is relative @@ -26,7 +26,7 @@ use std::ops::Mul; /// This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you /// update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag /// before the [`GlobalTransform`] is updated. -#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect)] +#[derive(Component, Debug, PartialEq, Clone, Copy, Reflect, FromReflect)] #[reflect(Component, Default, PartialEq)] pub struct Transform { /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. diff --git a/crates/bevy_ui/src/focus.rs b/crates/bevy_ui/src/focus.rs index b9ef20069e9a3..75333dc500419 100644 --- a/crates/bevy_ui/src/focus.rs +++ b/crates/bevy_ui/src/focus.rs @@ -7,7 +7,7 @@ use bevy_ecs::{ }; use bevy_input::{mouse::MouseButton, touch::Touches, Input}; use bevy_math::Vec2; -use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_render::camera::{Camera, RenderTarget}; use bevy_render::view::ComputedVisibility; use bevy_transform::components::GlobalTransform; @@ -31,7 +31,17 @@ use smallvec::SmallVec; /// Note that you can also control the visibility of a node using the [`Display`](crate::ui_node::Display) property, /// which fully collapses it during layout calculations. #[derive( - Component, Copy, Clone, Default, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize, + Component, + Copy, + Clone, + Default, + Eq, + PartialEq, + Debug, + Reflect, + FromReflect, + Serialize, + Deserialize, )] #[reflect_value(Component, Serialize, Deserialize, PartialEq)] pub enum Interaction { @@ -46,7 +56,17 @@ pub enum Interaction { /// Describes whether the node should block interactions with lower nodes #[derive( - Component, Copy, Clone, Default, Eq, PartialEq, Debug, Reflect, Serialize, Deserialize, + Component, + Copy, + Clone, + Default, + Eq, + PartialEq, + Debug, + Reflect, + FromReflect, + Serialize, + Deserialize, )] #[reflect_value(Component, Serialize, Deserialize, PartialEq)] pub enum FocusPolicy { diff --git a/crates/bevy_ui/src/geometry.rs b/crates/bevy_ui/src/geometry.rs index 620e96225def8..f280aea1c2627 100644 --- a/crates/bevy_ui/src/geometry.rs +++ b/crates/bevy_ui/src/geometry.rs @@ -1,6 +1,6 @@ use crate::Val; use bevy_math::Vec2; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; /// A type which is commonly used to define positions, margins, paddings and borders. @@ -120,7 +120,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; /// bottom: Val::Px(40.0), /// }; /// ``` -#[derive(Copy, Clone, PartialEq, Debug, Default, Reflect)] +#[derive(Copy, Clone, PartialEq, Debug, Default, Reflect, FromReflect)] #[reflect(PartialEq)] pub struct UiRect { /// The value corresponding to the left side of the UI rect. @@ -189,7 +189,7 @@ impl UiRect { /// A 2-dimensional area defined by a width and height. /// /// It is commonly used to define the size of a text or UI element. -#[derive(Copy, Clone, PartialEq, Debug, Default, Reflect)] +#[derive(Copy, Clone, PartialEq, Debug, Default, Reflect, FromReflect)] #[reflect(PartialEq)] pub struct Size { /// The width of the 2-dimensional area. diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 4483e03aa7ebf..9c01e2117fb50 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -4,6 +4,7 @@ use bevy_derive::{Deref, DerefMut}; use bevy_ecs::{prelude::Component, reflect::ReflectComponent}; use bevy_math::Vec2; use bevy_reflect::prelude::*; +use bevy_reflect::FromReflect; use bevy_render::{ color::Color, texture::{Image, DEFAULT_IMAGE_HANDLE}, @@ -12,7 +13,7 @@ use serde::{Deserialize, Serialize}; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; /// Describes the size of a UI node -#[derive(Component, Debug, Clone, Default, Reflect)] +#[derive(Component, Debug, Clone, Default, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct Node { /// The size of the node as width and height in pixels @@ -20,7 +21,7 @@ pub struct Node { } /// An enum that describes possible types of value in flexbox layout options -#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive(Copy, Clone, PartialEq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum Val { /// No value defined @@ -128,7 +129,7 @@ impl DivAssign for Val { /// /// **Note:** Bevy's UI is upside down compared to how Flexbox normally works, to stay consistent with engine paradigms about layouting from /// the upper left corner of the display -#[derive(Component, Clone, PartialEq, Debug, Reflect)] +#[derive(Component, Clone, PartialEq, Debug, Reflect, FromReflect)] #[reflect(Component, Default, PartialEq)] pub struct Style { /// Whether to arrange this node and its children with flexbox layout @@ -207,7 +208,9 @@ impl Default for Style { } /// How items are aligned according to the cross axis -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum AlignItems { /// Items are aligned at the start @@ -224,7 +227,9 @@ pub enum AlignItems { } /// Works like [`AlignItems`] but applies only to a single item -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum AlignSelf { /// Use the value of [`AlignItems`] @@ -245,7 +250,9 @@ pub enum AlignSelf { /// Defines how each line is aligned within the flexbox. /// /// It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items. -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum AlignContent { /// Each line moves towards the start of the cross axis @@ -268,7 +275,9 @@ pub enum AlignContent { /// Defines the text direction /// /// For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum Direction { /// Inherit from parent node @@ -283,7 +292,9 @@ pub enum Direction { /// Whether to use a Flexbox layout model. /// /// Part of the [`Style`] component. -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum Display { /// Use Flexbox layout model to determine the position of this [`Node`]. @@ -297,7 +308,9 @@ pub enum Display { } /// Defines how flexbox items are ordered within a flexbox -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum FlexDirection { /// Same way as text direction along the main axis @@ -312,7 +325,9 @@ pub enum FlexDirection { } /// Defines how items are aligned according to the main axis -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum JustifyContent { /// Pushed towards the start @@ -331,7 +346,9 @@ pub enum JustifyContent { } /// Whether to show or hide overflowing items -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Reflect, Serialize, Deserialize)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Reflect, FromReflect, Serialize, Deserialize, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum Overflow { /// Show overflowing items @@ -342,7 +359,9 @@ pub enum Overflow { } /// The strategy used to position this node -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum PositionType { /// Relative to all other nodes with the [`PositionType::Relative`] value @@ -355,7 +374,9 @@ pub enum PositionType { } /// Defines if flexbox items appear on a single line or on multiple lines -#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect)] +#[derive( + Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, Reflect, FromReflect, +)] #[reflect_value(PartialEq, Serialize, Deserialize)] pub enum FlexWrap { /// Single line, will overflow if needed @@ -368,7 +389,7 @@ pub enum FlexWrap { } /// The calculated size of the node -#[derive(Component, Default, Copy, Clone, Debug, Reflect)] +#[derive(Component, Default, Copy, Clone, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct CalculatedSize { /// The size of the node @@ -376,7 +397,7 @@ pub struct CalculatedSize { } /// The color of the node -#[derive(Component, Default, Copy, Clone, Debug, Reflect)] +#[derive(Component, Default, Copy, Clone, Debug, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct UiColor(pub Color); @@ -387,7 +408,7 @@ impl From for UiColor { } /// The image of the node -#[derive(Component, Clone, Debug, Reflect, Deref, DerefMut)] +#[derive(Component, Clone, Debug, Reflect, FromReflect, Deref, DerefMut)] #[reflect(Component, Default)] pub struct UiImage(pub Handle); @@ -404,7 +425,7 @@ impl From> for UiImage { } /// The calculated clip of the node -#[derive(Component, Default, Copy, Clone, Debug, Reflect)] +#[derive(Component, Default, Copy, Clone, Debug, Reflect, FromReflect)] #[reflect(Component)] pub struct CalculatedClip { /// The rect of the clip diff --git a/crates/bevy_ui/src/widget/button.rs b/crates/bevy_ui/src/widget/button.rs index 6c7dced0f3bb0..f5b0f73375715 100644 --- a/crates/bevy_ui/src/widget/button.rs +++ b/crates/bevy_ui/src/widget/button.rs @@ -1,9 +1,9 @@ use bevy_ecs::prelude::Component; use bevy_ecs::reflect::ReflectComponent; use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::Reflect; +use bevy_reflect::{FromReflect, Reflect}; /// Marker struct for buttons -#[derive(Component, Debug, Default, Clone, Copy, Reflect)] +#[derive(Component, Debug, Default, Clone, Copy, Reflect, FromReflect)] #[reflect(Component, Default)] pub struct Button; diff --git a/crates/bevy_ui/src/widget/image.rs b/crates/bevy_ui/src/widget/image.rs index f922378f60d35..d43e673c24809 100644 --- a/crates/bevy_ui/src/widget/image.rs +++ b/crates/bevy_ui/src/widget/image.rs @@ -6,12 +6,12 @@ use bevy_ecs::{ reflect::ReflectComponent, system::{Query, Res}, }; -use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; +use bevy_reflect::{FromReflect, Reflect, ReflectDeserialize, ReflectSerialize}; use bevy_render::texture::Image; use serde::{Deserialize, Serialize}; /// Describes how to resize the Image node -#[derive(Component, Debug, Default, Clone, Reflect, Serialize, Deserialize)] +#[derive(Component, Debug, Default, Clone, Reflect, FromReflect, Serialize, Deserialize)] #[reflect_value(Component, Serialize, Deserialize)] pub enum ImageMode { /// Keep the aspect ratio of the image diff --git a/examples/scene/scene.rs b/examples/scene/scene.rs index 66689e2a8b5f2..28262a10d044e 100644 --- a/examples/scene/scene.rs +++ b/examples/scene/scene.rs @@ -1,5 +1,6 @@ //! This example illustrates loading scenes from files. +use bevy::reflect::FromReflect; use bevy::{prelude::*, reflect::TypeRegistry, utils::Duration}; fn main() { @@ -20,7 +21,7 @@ fn main() { // 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 // FromResources). The simplest registered component just needs these two derives: -#[derive(Component, Reflect, Default)] +#[derive(Component, Reflect, FromReflect, Default)] #[reflect(Component)] // this tells the reflect derive to also reflect component behaviors struct ComponentA { pub x: f32, @@ -31,7 +32,7 @@ struct ComponentA { // ignored with the #[reflect(ignore)] 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)] +#[derive(Component, Reflect, FromReflect)] #[reflect(Component)] struct ComponentB { pub value: String,