From 7865248178f1f3a23c7f6ae8ac83cc43ef428632 Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Fri, 17 Jan 2025 20:52:49 -0800 Subject: [PATCH] Feature gate bevy_reflect --- crates/bevy_ecs/src/hierarchy.rs | 54 ++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/crates/bevy_ecs/src/hierarchy.rs b/crates/bevy_ecs/src/hierarchy.rs index dd82d4bed00f1..6e495a116b7f9 100644 --- a/crates/bevy_ecs/src/hierarchy.rs +++ b/crates/bevy_ecs/src/hierarchy.rs @@ -6,24 +6,22 @@ //! [`Relationship`]: crate::relationship::Relationship //! [`RelationshipTarget`]: crate::relationship::RelationshipTarget -use crate as bevy_ecs; -use crate::bundle::Bundle; -use crate::component::ComponentId; -use crate::relationship::{RelatedSpawner, RelatedSpawnerCommands}; -use crate::system::EntityCommands; -use crate::world::{DeferredWorld, EntityWorldMut}; +#[cfg(feature = "bevy_reflect")] +use crate::reflect::{ + ReflectComponent, ReflectFromWorld, ReflectMapEntities, ReflectVisitEntities, + ReflectVisitEntitiesMut, +}; use crate::{ - component::Component, + self as bevy_ecs, + bundle::Bundle, + component::{Component, ComponentId}, entity::{Entity, VisitEntities}, - reflect::{ - ReflectComponent, ReflectFromWorld, ReflectMapEntities, ReflectVisitEntities, - ReflectVisitEntitiesMut, - }, - world::{FromWorld, World}, + relationship::{RelatedSpawner, RelatedSpawnerCommands}, + system::EntityCommands, + world::{DeferredWorld, EntityWorldMut, FromWorld, World}, }; use alloc::{format, string::String, vec::Vec}; use bevy_ecs_macros::VisitEntitiesMut; -use bevy_reflect::Reflect; use core::ops::Deref; use core::slice; use disqualified::ShortName; @@ -92,15 +90,19 @@ use log::warn; /// assert_eq!(&**world.entity(root).get::().unwrap(), &[child1, child2]); /// assert_eq!(&**world.entity(child1).get::().unwrap(), &[grandchild]); /// ``` -#[derive(Component, Clone, Reflect, VisitEntities, VisitEntitiesMut, PartialEq, Eq, Debug)] -#[reflect( - Component, - MapEntities, - VisitEntities, - VisitEntitiesMut, - PartialEq, - Debug, - FromWorld +#[derive(Component, Clone, VisitEntities, VisitEntitiesMut, PartialEq, Eq, Debug)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] +#[cfg_attr( + feature = "bevy_reflect", + reflect( + Component, + MapEntities, + VisitEntities, + VisitEntitiesMut, + PartialEq, + Debug, + FromWorld + ) )] #[relationship(relationship_target = Children)] pub struct Parent(pub Entity); @@ -137,9 +139,13 @@ impl FromWorld for Parent { /// /// Together, these components form the "canonical parent-child hierarchy". See the [`Parent`] component for all full /// description of this relationship and instructions on how to use it. -#[derive(Component, Default, Reflect, VisitEntitiesMut, Debug, PartialEq, Eq)] +#[derive(Component, Default, VisitEntitiesMut, Debug, PartialEq, Eq)] #[relationship_target(relationship = Parent, despawn_descendants)] -#[reflect(Component, MapEntities, VisitEntities, VisitEntitiesMut, FromWorld)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] +#[cfg_attr( + feature = "bevy_reflect", + reflect(Component, MapEntities, VisitEntities, VisitEntitiesMut, FromWorld) +)] pub struct Children(Vec); impl<'a> IntoIterator for &'a Children {