Struct Added
pub struct Added<T>(/* private fields */);Expand description
A filter on a component that only retains results the first time after they have been added.
A common use for this filter is one-time initialization.
To retain all results without filtering but still check whether they were added after the
system last ran, use Ref<T>.
Note that this includes changes that happened before the first time this Query was run.
§Deferred
Note, that entity modifications issued with Commands
are visible only after deferred operations are applied, typically after the system
that queued them.
§Time complexity
Added is not [ArchetypeFilter], which practically means that
if the query (with T component filter) matches a million entities,
Added<T> filter will iterate over all of them even if none of them were just added.
For example, these two systems are roughly equivalent in terms of performance:
fn system1(q: Query<&MyComponent, Added<Transform>>) {
for item in &q { /* component added */ }
}
fn system2(q: Query<(&MyComponent, Ref<Transform>)>) {
for item in &q {
if item.1.is_added() { /* component added */ }
}
}§Examples
fn print_add_name_component(query: Query<&Name, Added<Name>>) {
for name in &query {
println!("Named entity created: {:?}", name)
}
}
Trait Implementations§
§impl<T> QueryFilter for Added<T>where
T: Component,
impl<T> QueryFilter for Added<T>where
T: Component,
§const IS_ARCHETYPAL: bool = false
const IS_ARCHETYPAL: bool = false
§impl<T> WorldQuery for Added<T>where
T: Component,
impl<T> WorldQuery for Added<T>where
T: Component,
§const IS_DENSE: bool
const IS_DENSE: bool
§type Fetch<'w> = AddedFetch<'w, T>
type Fetch<'w> = AddedFetch<'w, T>
WorldQuery] to compute Self::Item for each entity.§type State = ComponentId
type State = ComponentId
Self::Fetch. This will be cached inside QueryState,
so it is best to move as much data / computation here as possible to reduce the cost of
constructing Self::Fetch.§fn shrink_fetch<'wlong, 'wshort>(
fetch: <Added<T> as WorldQuery>::Fetch<'wlong>,
) -> <Added<T> as WorldQuery>::Fetch<'wshort>where
'wlong: 'wshort,
fn shrink_fetch<'wlong, 'wshort>(
fetch: <Added<T> as WorldQuery>::Fetch<'wlong>,
) -> <Added<T> as WorldQuery>::Fetch<'wshort>where
'wlong: 'wshort,
§unsafe fn init_fetch<'w, 's>(
world: UnsafeWorldCell<'w>,
_: &'s ComponentId,
last_run: Tick,
this_run: Tick,
) -> <Added<T> as WorldQuery>::Fetch<'w>
unsafe fn init_fetch<'w, 's>( world: UnsafeWorldCell<'w>, _: &'s ComponentId, last_run: Tick, this_run: Tick, ) -> <Added<T> as WorldQuery>::Fetch<'w>
Self::Fetch,
by combining data from the World with the cached Self::State.
Readonly accesses resources registered in [WorldQuery::update_component_access]. Read more§unsafe fn set_archetype<'w, 's>(
fetch: &mut <Added<T> as WorldQuery>::Fetch<'w>,
component_id: &'s ComponentId,
_archetype: &'w Archetype,
table: &'w Table,
)
unsafe fn set_archetype<'w, 's>( fetch: &mut <Added<T> as WorldQuery>::Fetch<'w>, component_id: &'s ComponentId, _archetype: &'w Archetype, table: &'w Table, )
Archetype]. This will always be called on
archetypes that match this [WorldQuery]. Read more§unsafe fn set_table<'w, 's>(
fetch: &mut <Added<T> as WorldQuery>::Fetch<'w>,
_: &'s ComponentId,
table: &'w Table,
)
unsafe fn set_table<'w, 's>( fetch: &mut <Added<T> as WorldQuery>::Fetch<'w>, _: &'s ComponentId, table: &'w Table, )
Table]. This will always be called on tables
that match this [WorldQuery]. Read more§fn update_component_access(_: &ComponentId, access: &mut FilteredAccess)
fn update_component_access(_: &ComponentId, access: &mut FilteredAccess)
§fn init_state(world: &mut World) -> ComponentId
fn init_state(world: &mut World) -> ComponentId
State for this [WorldQuery] type.§fn matches_component_set(
_: &ComponentId,
set_contains_id: &impl Fn(ComponentId) -> bool,
) -> bool
fn matches_component_set( _: &ComponentId, set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool
§fn init_nested_access(
_state: &Self::State,
_system_name: Option<&str>,
_component_access_set: &mut FilteredAccessSet,
_world: UnsafeWorldCell<'_>,
)
fn init_nested_access( _state: &Self::State, _system_name: Option<&str>, _component_access_set: &mut FilteredAccessSet, _world: UnsafeWorldCell<'_>, )
WorldQuery]. Read more