diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 2687f7eb16ad0..812e01c99cb10 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -2187,7 +2187,8 @@ mod tests { }) .id(); - assert!(world.entity(id).get::().is_some()); + assert!(world.entity(id).get::().is_some()); + assert!(world.entity(id).get::().is_none()); } #[test] diff --git a/crates/bevy_ecs/src/hierarchy.rs b/crates/bevy_ecs/src/hierarchy.rs index d99e89b355e7e..0e05ce992d373 100644 --- a/crates/bevy_ecs/src/hierarchy.rs +++ b/crates/bevy_ecs/src/hierarchy.rs @@ -475,8 +475,8 @@ pub fn validate_parent_has_component( } } -/// Returns a [`SpawnRelatedBundle`] that will insert the [`Children`] component, spawn a [`SpawnableList`] of entities with given bundles that -/// relate to the [`Children`] entity via the [`ChildOf`] component, and reserve space in the [`Children`] for each spawned entity. +/// Returns a [`SpawnRelatedBundle`] that will spawn a [`SpawnableList`] of entities with given bundles that +/// relate to the [`Children`] entity via the [`ChildOf`] component. /// /// Any additional arguments will be interpreted as bundles to be spawned. /// diff --git a/crates/bevy_ecs/src/spawn.rs b/crates/bevy_ecs/src/spawn.rs index d5014f22409fd..96ff2a41d0f11 100644 --- a/crates/bevy_ecs/src/spawn.rs +++ b/crates/bevy_ecs/src/spawn.rs @@ -163,9 +163,7 @@ macro_rules! spawnable_list_impl { all_tuples!(spawnable_list_impl, 0, 12, P); -/// A [`Bundle`] that: -/// 1. Contains a [`RelationshipTarget`] component (associated with the given [`Relationship`]). This reserves space for the [`SpawnableList`]. -/// 2. Spawns a [`SpawnableList`] of related entities with a given [`Relationship`]. +/// A [`Bundle`] that spawns a [`SpawnableList`] of related entities with a given [`Relationship`]. /// /// This is intended to be created using [`SpawnRelated`]. pub struct SpawnRelatedBundle> { @@ -182,32 +180,26 @@ impl> BundleEffect for SpawnRelatedBundle + Send + Sync + 'static> Bundle for SpawnRelatedBundle { fn component_ids( - components: &mut crate::component::ComponentsRegistrator, - ids: &mut impl FnMut(crate::component::ComponentId), + _components: &mut crate::component::ComponentsRegistrator, + _ids: &mut impl FnMut(crate::component::ComponentId), ) { - ::component_ids(components, ids); } fn get_component_ids( - components: &crate::component::Components, - ids: &mut impl FnMut(Option), + _components: &crate::component::Components, + _ids: &mut impl FnMut(Option), ) { - ::get_component_ids(components, ids); } fn register_required_components( - components: &mut crate::component::ComponentsRegistrator, - required_components: &mut crate::component::RequiredComponents, + _components: &mut crate::component::ComponentsRegistrator, + _required_components: &mut crate::component::RequiredComponents, ) { - ::register_required_components( - components, - required_components, - ); } } impl> DynamicBundle for SpawnRelatedBundle { @@ -215,17 +207,13 @@ impl> DynamicBundle for SpawnRelatedBundle< fn get_components( self, - func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>), + _func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>), ) -> Self::Effect { - ::with_capacity(self.list.size_hint()) - .get_components(func); self } } -/// A [`Bundle`] that: -/// 1. Contains a [`RelationshipTarget`] component (associated with the given [`Relationship`]). This reserves space for a single entity. -/// 2. Spawns a single related entity containing the given `B` [`Bundle`] and the given [`Relationship`]. +/// A [`Bundle`] that spawns a single related entity containing the given `B` [`Bundle`] and the given [`Relationship`]. /// /// This is intended to be created using [`SpawnRelated`]. pub struct SpawnOneRelated { @@ -244,54 +232,45 @@ impl DynamicBundle for SpawnOneRelated { fn get_components( self, - func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>), + _func: &mut impl FnMut(crate::component::StorageType, bevy_ptr::OwningPtr<'_>), ) -> Self::Effect { - ::with_capacity(1).get_components(func); self } } -// SAFETY: This internally relies on the RelationshipTarget's Bundle implementation, which is sound. +// SAFETY: This is a blank implementation. unsafe impl Bundle for SpawnOneRelated { fn component_ids( - components: &mut crate::component::ComponentsRegistrator, - ids: &mut impl FnMut(crate::component::ComponentId), + _components: &mut crate::component::ComponentsRegistrator, + _ids: &mut impl FnMut(crate::component::ComponentId), ) { - ::component_ids(components, ids); } fn get_component_ids( - components: &crate::component::Components, - ids: &mut impl FnMut(Option), + _components: &crate::component::Components, + _ids: &mut impl FnMut(Option), ) { - ::get_component_ids(components, ids); } fn register_required_components( - components: &mut crate::component::ComponentsRegistrator, - required_components: &mut crate::component::RequiredComponents, + _components: &mut crate::component::ComponentsRegistrator, + _required_components: &mut crate::component::RequiredComponents, ) { - ::register_required_components( - components, - required_components, - ); } } -/// [`RelationshipTarget`] methods that create a [`Bundle`] with a [`DynamicBundle::Effect`] that: -/// -/// 1. Contains the [`RelationshipTarget`] component, pre-allocated with the necessary space for spawned entities. -/// 2. Spawns an entity (or a list of entities) that relate to the entity the [`Bundle`] is added to via the [`RelationshipTarget::Relationship`]. +/// [`RelationshipTarget`] methods that create a [`Bundle`] with a [`DynamicBundle::Effect`] that +/// spawns an entity (or a list of entities) that relate to the entity the [`Bundle`] is added to via the [`RelationshipTarget::Relationship`]. pub trait SpawnRelated: RelationshipTarget { - /// Returns a [`Bundle`] containing this [`RelationshipTarget`] component. It also spawns a [`SpawnableList`] of entities, each related to the bundle's entity - /// via [`RelationshipTarget::Relationship`]. The [`RelationshipTarget`] (when possible) will pre-allocate space for the related entities. + /// Returns a [`Bundle`] that spawns a [`SpawnableList`] of entities, each related to the bundle's entity + /// via [`RelationshipTarget::Relationship`]. /// /// See [`Spawn`], [`SpawnIter`], and [`SpawnWith`] for usage examples. fn spawn>( list: L, ) -> SpawnRelatedBundle; - /// Returns a [`Bundle`] containing this [`RelationshipTarget`] component. It also spawns a single entity containing [`Bundle`] that is related to the bundle's entity + /// Returns a [`Bundle`] that spawns a single entity containing [`Bundle`] that is related to the bundle's entity /// via [`RelationshipTarget::Relationship`]. /// /// ``` @@ -326,8 +305,8 @@ impl SpawnRelated for T { } } -/// Returns a [`SpawnRelatedBundle`] that will insert the given [`RelationshipTarget`], spawn a [`SpawnableList`] of entities with given bundles that -/// relate to the [`RelationshipTarget`] entity via the [`RelationshipTarget::Relationship`] component, and reserve space in the [`RelationshipTarget`] for each spawned entity. +/// Returns a [`SpawnRelatedBundle`] that will spawn a [`SpawnableList`] of entities with given bundles that +/// relate to the [`RelationshipTarget`] entity via the [`RelationshipTarget::Relationship`] component. /// /// The first argument is the [`RelationshipTarget`] type. Any additional arguments will be interpreted as bundles to be spawned. ///