Struct RemovedComponents
pub struct RemovedComponents<'w, 's, T>where
T: Component,{ /* private fields */ }Expand description
A [SystemParam] that yields entities that had their T Component
removed or have been despawned with it.
This acts effectively the same as a MessageReader.
Unlike hooks or observers (see the lifecycle module docs), this does not allow you to see which data existed before removal.
If you are using bevy_ecs as a standalone crate,
note that the RemovedComponents list will not be automatically cleared for you,
and will need to be manually flushed using World::clear_trackers.
For users of bevy and bevy_app, World::clear_trackers is
automatically called by bevy_app::App::update and bevy_app::SubApp::update.
For the main world, this is delayed until after all SubApps have run.
§Examples
Basic usage:
fn react_on_removal(mut removed: RemovedComponents<MyComponent>) {
removed.read().for_each(|removed_entity| println!("{}", removed_entity));
}Implementations§
§impl<'w, 's, T> RemovedComponents<'w, 's, T>where
T: Component,
impl<'w, 's, T> RemovedComponents<'w, 's, T>where
T: Component,
pub fn reader(&self) -> &MessageCursor<RemovedComponentEntity>
pub fn reader(&self) -> &MessageCursor<RemovedComponentEntity>
Fetch underlying [MessageCursor].
pub fn reader_mut(&mut self) -> &mut MessageCursor<RemovedComponentEntity>
pub fn reader_mut(&mut self) -> &mut MessageCursor<RemovedComponentEntity>
Fetch underlying [MessageCursor] mutably.
pub fn reader_mut_with_messages(
&mut self,
) -> Option<(&mut RemovedComponentReader<T>, &Messages<RemovedComponentEntity>)>
pub fn reader_mut_with_messages( &mut self, ) -> Option<(&mut RemovedComponentReader<T>, &Messages<RemovedComponentEntity>)>
Destructures to get a mutable reference to the MessageCursor
and a reference to Messages.
This is necessary since Rust can’t detect destructuring through methods and most
usecases of the reader uses the Messages as well.
pub fn read(
&mut self,
) -> Map<Flatten<IntoIter<Cloned<MessageIterator<'_, RemovedComponentEntity>>>>, fn(RemovedComponentEntity) -> Entity>
pub fn read( &mut self, ) -> Map<Flatten<IntoIter<Cloned<MessageIterator<'_, RemovedComponentEntity>>>>, fn(RemovedComponentEntity) -> Entity>
Iterates over the messages this RemovedComponents has not seen yet. This updates the
RemovedComponents’s message counter, which means subsequent message reads will not include messages
that happened before now.
pub fn read_with_id(
&mut self,
) -> Map<Flatten<IntoIter<MessageIteratorWithId<'_, RemovedComponentEntity>>>, fn((&RemovedComponentEntity, MessageId<RemovedComponentEntity>)) -> (Entity, MessageId<RemovedComponentEntity>)>
pub fn read_with_id( &mut self, ) -> Map<Flatten<IntoIter<MessageIteratorWithId<'_, RemovedComponentEntity>>>, fn((&RemovedComponentEntity, MessageId<RemovedComponentEntity>)) -> (Entity, MessageId<RemovedComponentEntity>)>
Like read, except also returning the [MessageId] of the messages.
pub fn len(&self) -> usize
pub fn len(&self) -> usize
Determines the number of removal messages available to be read from this RemovedComponents without consuming any.
pub fn clear(&mut self)
pub fn clear(&mut self)
Consumes all available messages.
This means these messages will not appear in calls to RemovedComponents::read() or
RemovedComponents::read_with_id() and RemovedComponents::is_empty() will return true.
Trait Implementations§
§impl<T> SystemParam for RemovedComponents<'_, '_, T>where
T: Component,
impl<T> SystemParam for RemovedComponents<'_, '_, T>where
T: Component,
§type Item<'w, 's> = RemovedComponents<'w, 's, T>
type Item<'w, 's> = RemovedComponents<'w, 's, T>
Self, instantiated with new lifetimes. Read more§fn init_state(
world: &mut World,
) -> <RemovedComponents<'_, '_, T> as SystemParam>::State
fn init_state( world: &mut World, ) -> <RemovedComponents<'_, '_, T> as SystemParam>::State
State.§fn init_access(
state: &<RemovedComponents<'_, '_, T> as SystemParam>::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &<RemovedComponents<'_, '_, T> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
§fn apply(
state: &mut <RemovedComponents<'_, '_, T> as SystemParam>::State,
system_meta: &SystemMeta,
world: &mut World,
)
fn apply( state: &mut <RemovedComponents<'_, '_, T> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )
SystemParam]’s state.
This is used to apply Commands during ApplyDeferred.§fn queue(
state: &mut <RemovedComponents<'_, '_, T> as SystemParam>::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut <RemovedComponents<'_, '_, T> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
ApplyDeferred.§unsafe fn get_param<'w, 's>(
state: &'s mut <RemovedComponents<'_, '_, T> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Result<<RemovedComponents<'_, '_, T> as SystemParam>::Item<'w, 's>, SystemParamValidationError>
unsafe fn get_param<'w, 's>( state: &'s mut <RemovedComponents<'_, '_, T> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Result<<RemovedComponents<'_, '_, T> as SystemParam>::Item<'w, 's>, SystemParamValidationError>
SystemParamFunction. Read more