Skip to content

Add a TimedCommands SystemParam for easier delayed operations #15129

@ItsDoot

Description

@ItsDoot

What problem does this solve or what need does it fill?

Queuing things to run at a specific later point in time is a pretty common requirement for many games, but our current setup for doing this type of thing is pretty boilerplate-heavy: see one example in the repo: https://github.com/bevyengine/bevy/blob/90bb1adeb28b82be96546e0c2cde81530241f7af/examples/time/timers.rs

What solution would you like?

Especially for situations where batch processing is not needed, we should be able to queue commands to happen at a specific future point in time, so a TimedCommands SystemParam would make sense:

pub fn foo_system(mut commands: Commands, mut timed_commands: TimedCommands, my_entity: Query<Entity, With<Foo>>) {
    let my_entity = my_entity.single();

    // Normally you might queue a command, and it would apply at the very next sync point:
    commands.entity(my_entity).insert(Bar);
    
    // However, with TimedCommands you would queue it to run a specific duration from now.
    // This would run at the soonest sync point after the duration has passed.
    timed_commands.after(Duration::from_secs(5)).entity(my_entity).insert(Bar);
}

HOWEVER, developers might run into issues where entities get despawned or changed between the time when the command was queued and when it gets applied, so we should take care with what kinds of operations we allow through TimedCommands.

What alternative(s) have you considered?

Continue with our current boilerplate-heavy solution.

Metadata

Metadata

Labels

A-ECSEntities, components, systems, and eventsA-TimeInvolves time keeping and reportingC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions