Switch EntityWorldMut::retain to StaticBundle

This commit is contained in:
Giacomo Stevanato 2025-06-02 18:44:49 +02:00
parent 28a21bdaf3
commit c33033a5e7
No known key found for this signature in database
3 changed files with 9 additions and 6 deletions

View File

@ -190,9 +190,9 @@ pub fn clear() -> impl EntityCommand {
} }
/// An [`EntityCommand`] that removes all components from an entity, /// An [`EntityCommand`] that removes all components from an entity,
/// except for those in the given [`Bundle`]. /// except for those in the given [`StaticBundle`].
#[track_caller] #[track_caller]
pub fn retain<T: Bundle>() -> impl EntityCommand { pub fn retain<T: StaticBundle>() -> impl EntityCommand {
let caller = MaybeLocation::caller(); let caller = MaybeLocation::caller();
move |mut entity: EntityWorldMut| { move |mut entity: EntityWorldMut| {
entity.retain_with_caller::<T>(caller); entity.retain_with_caller::<T>(caller);

View File

@ -1943,7 +1943,7 @@ impl<'a> EntityCommands<'a> {
/// # bevy_ecs::system::assert_is_system(remove_combat_stats_system); /// # bevy_ecs::system::assert_is_system(remove_combat_stats_system);
/// ``` /// ```
#[track_caller] #[track_caller]
pub fn retain<B: Bundle>(&mut self) -> &mut Self { pub fn retain<B: StaticBundle>(&mut self) -> &mut Self {
self.queue(entity_command::retain::<B>()) self.queue(entity_command::retain::<B>())
} }

View File

@ -2151,12 +2151,15 @@ impl<'w> EntityWorldMut<'w> {
/// ///
/// If the entity has been despawned while this `EntityWorldMut` is still alive. /// If the entity has been despawned while this `EntityWorldMut` is still alive.
#[track_caller] #[track_caller]
pub fn retain<T: Bundle>(&mut self) -> &mut Self { pub fn retain<T: StaticBundle>(&mut self) -> &mut Self {
self.retain_with_caller::<T>(MaybeLocation::caller()) self.retain_with_caller::<T>(MaybeLocation::caller())
} }
#[inline] #[inline]
pub(crate) fn retain_with_caller<T: Bundle>(&mut self, caller: MaybeLocation) -> &mut Self { pub(crate) fn retain_with_caller<T: StaticBundle>(
&mut self,
caller: MaybeLocation,
) -> &mut Self {
let old_location = self.location(); let old_location = self.location();
let archetypes = &mut self.world.archetypes; let archetypes = &mut self.world.archetypes;
let storages = &mut self.world.storages; let storages = &mut self.world.storages;
@ -2168,7 +2171,7 @@ impl<'w> EntityWorldMut<'w> {
let retained_bundle = self let retained_bundle = self
.world .world
.bundles .bundles
.register_info::<T>(&mut registrator, storages); .register_static_info::<T>(&mut registrator, storages);
// SAFETY: `retained_bundle` exists as we just initialized it. // SAFETY: `retained_bundle` exists as we just initialized it.
let retained_bundle_info = unsafe { self.world.bundles.get_unchecked(retained_bundle) }; let retained_bundle_info = unsafe { self.world.bundles.get_unchecked(retained_bundle) };
let old_archetype = &mut archetypes[old_location.archetype_id]; let old_archetype = &mut archetypes[old_location.archetype_id];