Struct ParallelCommands
pub struct ParallelCommands<'w, 's> { /* private fields */ }Expand description
An alternative to Commands that can be used in parallel contexts, such as those
in Query::par_iter.
For cases where multiple non-computation-heavy (lightweight) bundles of the same
Bundle type need to be spawned, consider using
Commands::spawn_batch for better performance.
§Note
Because command application order will depend on how many threads are ran, non-commutative commands may result in non-deterministic results.
§Example
fn parallel_command_system(
mut query: Query<(Entity, &Velocity)>,
par_commands: ParallelCommands
) {
query.par_iter().for_each(|(entity, velocity)| {
if velocity.magnitude() > 10.0 {
par_commands.command_scope(|mut commands| {
commands.entity(entity).despawn();
});
}
});
}Implementations§
§impl<'w, 's> ParallelCommands<'w, 's>
impl<'w, 's> ParallelCommands<'w, 's>
pub fn command_scope<R>(&self, f: impl FnOnce(Commands<'_, '_>) -> R) -> R
pub fn command_scope<R>(&self, f: impl FnOnce(Commands<'_, '_>) -> R) -> R
Temporarily provides access to the Commands for the current thread.
For an example, see the type-level documentation for ParallelCommands.
Trait Implementations§
§impl SystemParam for ParallelCommands<'_, '_>
impl SystemParam for ParallelCommands<'_, '_>
§type Item<'w, 's> = ParallelCommands<'w, 's>
type Item<'w, 's> = ParallelCommands<'w, 's>
The item type returned when constructing this system param.
The value of this associated type should be
Self, instantiated with new lifetimes. Read more§fn init_state(
world: &mut World,
) -> <ParallelCommands<'_, '_> as SystemParam>::State
fn init_state( world: &mut World, ) -> <ParallelCommands<'_, '_> as SystemParam>::State
Creates a new instance of this param’s
State.§fn init_access(
state: &<ParallelCommands<'_, '_> as SystemParam>::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &<ParallelCommands<'_, '_> as SystemParam>::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
§fn apply(
state: &mut <ParallelCommands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: &mut World,
)
fn apply( state: &mut <ParallelCommands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: &mut World, )
Applies any deferred mutations stored in this [
SystemParam]’s state.
This is used to apply Commands during ApplyDeferred.§fn queue(
state: &mut <ParallelCommands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut <ParallelCommands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
Queues any deferred mutations to be applied at the next
ApplyDeferred.§unsafe fn get_param<'w, 's>(
state: &'s mut <ParallelCommands<'_, '_> as SystemParam>::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Result<<ParallelCommands<'_, '_> as SystemParam>::Item<'w, 's>, SystemParamValidationError>
unsafe fn get_param<'w, 's>( state: &'s mut <ParallelCommands<'_, '_> as SystemParam>::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Result<<ParallelCommands<'_, '_> as SystemParam>::Item<'w, 's>, SystemParamValidationError>
Creates a parameter to be passed into a
SystemParamFunction. Read moreimpl<'w, 's> ReadOnlySystemParam for ParallelCommands<'w, 's>where
Deferred<'s, ParallelCommandQueue>: ReadOnlySystemParam,
&'w EntityAllocator: ReadOnlySystemParam,
&'w Entities: ReadOnlySystemParam,
Auto Trait Implementations§
impl<'w, 's> Freeze for ParallelCommands<'w, 's>
impl<'w, 's> RefUnwindSafe for ParallelCommands<'w, 's>
impl<'w, 's> Send for ParallelCommands<'w, 's>
impl<'w, 's> Sync for ParallelCommands<'w, 's>
impl<'w, 's> Unpin for ParallelCommands<'w, 's>
impl<'w, 's> UnsafeUnpin for ParallelCommands<'w, 's>
impl<'w, 's> !UnwindSafe for ParallelCommands<'w, 's>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.