pub trait DelayedCommandsExt<'w> {
// Required method
fn delayed(&mut self) -> DelayedCommands<'w, '_>;
}Expand description
Extension trait for Commands that provides delayed command functionality.
Required Methods§
Sourcefn delayed(&mut self) -> DelayedCommands<'w, '_>
fn delayed(&mut self) -> DelayedCommands<'w, '_>
Returns a DelayedCommands instance that can be used to queue
commands to be submitted at a later point in time.
When dropped, the DelayedCommands submits spawn commands that will
spawn DelayedCommandQueue entities. The entities are checked
by the check_delayed_command_queues system, and their queues are
submitted when the specified time has elapsed.
§Usage
fn my_system(mut commands: Commands) {
// Spawn an entity after one second
commands.delayed().secs(1.0).spawn_empty();
}Entity allocation happens immediately even if the spawn command is delayed. This allows you to queue delayed commands on an entity that hasn’t been spawned yet.
fn my_system(mut commands: Commands) {
let mut delayed = commands.delayed();
// spawn an entity after 1 second, then despawn it a second later
let entity = delayed.secs(1.0).spawn_empty().id();
delayed.secs(2.0).entity(entity).despawn();
}§Timing
Delayed commands are currently checked against the default clock in the PreUpdate
schedule. There’s currently no way to specify different clocks for different
delayed commands - this is a limitation of the system and if you need this behavior
you’ll likely have to implement your own delay system.