diff --git a/crates/bevy_ecs/src/entity/hash.rs b/crates/bevy_ecs/src/entity/hash.rs index 0156951e7e302..b3de84e52d264 100644 --- a/crates/bevy_ecs/src/entity/hash.rs +++ b/crates/bevy_ecs/src/entity/hash.rs @@ -1,12 +1,14 @@ use std::hash::{BuildHasher, Hasher}; +#[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; use bevy_utils::hashbrown; use super::Entity; /// A [`BuildHasher`] that results in a [`EntityHasher`]. -#[derive(Default, Clone, Reflect)] +#[derive(Default, Clone)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] pub struct EntityHash; impl BuildHasher for EntityHash { @@ -85,11 +87,13 @@ pub type EntityHashSet = hashbrown::HashSet; #[cfg(test)] mod tests { use super::*; + #[cfg(feature = "bevy_reflect")] use bevy_reflect::Reflect; use static_assertions::assert_impl_all; // Check that the HashMaps are Clone if the key/values are Clone assert_impl_all!(EntityHashMap::: Clone); // EntityHashMap should implement Reflect + #[cfg(feature = "bevy_reflect")] assert_impl_all!(EntityHashMap::: Reflect); } diff --git a/crates/bevy_ecs/src/entity/mod.rs b/crates/bevy_ecs/src/entity/mod.rs index 54e62fa30e8dc..efc0a22458195 100644 --- a/crates/bevy_ecs/src/entity/mod.rs +++ b/crates/bevy_ecs/src/entity/mod.rs @@ -36,6 +36,7 @@ //! [`EntityWorldMut::insert`]: crate::world::EntityWorldMut::insert //! [`EntityWorldMut::remove`]: crate::world::EntityWorldMut::remove mod map_entities; +#[cfg(feature = "bevy_reflect")] use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize}; pub use map_entities::*; @@ -126,8 +127,12 @@ type IdCursor = isize; /// [`EntityCommands`]: crate::system::EntityCommands /// [`Query::get`]: crate::system::Query::get /// [`World`]: crate::world::World -#[derive(Clone, Copy, Reflect)] -#[reflect_value(Hash, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy)] +#[cfg_attr(feature = "bevy_reflect", derive(Reflect))] +#[cfg_attr( + feature = "bevy_reflect", + reflect_value(Hash, PartialEq, Serialize, Deserialize) +)] // Alignment repr necessary to allow LLVM to better output // optimised codegen for `to_bits`, `PartialEq` and `Ord`. #[repr(C, align(8))]