pub struct Spawned;Expand description
A filter that only retains results the first time after the entity has been spawned.
A common use for this filter is one-time initialization.
To retain all results without filtering but still check whether they were spawned after the
system last ran, use SpawnDetails instead.
Note that this includes entities that spawned before the first time this Query was run.
§Deferred
Note, that entity spawns issued with Commands
are visible only after deferred operations are applied, typically after the
system that queued them.
§Time complexity
Spawned is not ArchetypeFilter, which practically means that if query matches million
entities, Spawned filter will iterate over all of them even if none of them were spawned.
For example, these two systems are roughly equivalent in terms of performance:
fn system1(query: Query<Entity, Spawned>) {
for entity in &query { /* entity spawned */ }
}
fn system2(query: Query<(Entity, SpawnDetails)>) {
for (entity, spawned) in &query {
if spawned.is_spawned() { /* entity spawned */ }
}
}§Examples
fn print_spawning_entities(query: Query<&Name, Spawned>) {
for name in &query {
println!("Entity spawned: {:?}", name);
}
}
Trait Implementations§
Source§impl QueryFilter for Spawned
impl QueryFilter for Spawned
Source§const IS_ARCHETYPAL: bool = false
const IS_ARCHETYPAL: bool = false
Source§impl WorldQuery for Spawned
impl WorldQuery for Spawned
Source§const IS_DENSE: bool = true
const IS_DENSE: bool = true
Source§type Fetch<'w> = SpawnedFetch<'w>
type Fetch<'w> = SpawnedFetch<'w>
WorldQuery to compute Self::Item for each entity.Source§type State = ()
type State = ()
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.Source§fn shrink_fetch<'wlong: 'wshort, 'wshort>(
fetch: Self::Fetch<'wlong>,
) -> Self::Fetch<'wshort>
fn shrink_fetch<'wlong: 'wshort, 'wshort>( fetch: Self::Fetch<'wlong>, ) -> Self::Fetch<'wshort>
Source§unsafe fn init_fetch<'w, 's>(
world: UnsafeWorldCell<'w>,
_state: &'s (),
last_run: Tick,
this_run: Tick,
) -> Self::Fetch<'w>
unsafe fn init_fetch<'w, 's>( world: UnsafeWorldCell<'w>, _state: &'s (), last_run: Tick, this_run: Tick, ) -> Self::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 moreSource§unsafe fn set_archetype<'w, 's>(
_fetch: &mut Self::Fetch<'w>,
_state: &'s (),
_archetype: &'w Archetype,
_table: &'w Table,
)
unsafe fn set_archetype<'w, 's>( _fetch: &mut Self::Fetch<'w>, _state: &'s (), _archetype: &'w Archetype, _table: &'w Table, )
Archetype. This will always be called on
archetypes that match this WorldQuery. Read moreSource§unsafe fn set_table<'w, 's>(
_fetch: &mut Self::Fetch<'w>,
_state: &'s (),
_table: &'w Table,
)
unsafe fn set_table<'w, 's>( _fetch: &mut Self::Fetch<'w>, _state: &'s (), _table: &'w Table, )
Table. This will always be called on tables
that match this WorldQuery. Read moreSource§fn update_component_access(_state: &(), _access: &mut FilteredAccess)
fn update_component_access(_state: &(), _access: &mut FilteredAccess)
Source§fn init_state(_world: &mut World)
fn init_state(_world: &mut World)
State for this WorldQuery type.