Closed alice-i-cecile closed 5 days ago
I feel like this would be adding specifics for something that could be modeled with a component containing a Timer + leveraging Trigger observer:
example API:
command.spawn(
TimerWithEvent(
Timer::new(Duration::from_secs(1),TimerMode::Once)
)
).observe(|trigger: Trigger<TimerFinished>, mut commands: Commands| {
// TODO: anything useful
commands.entity(trigger.entity).despawn();
}
Also see this issue: https://github.com/bevyengine/bevy/issues/15129
Using an observer is nice! It does mean that we can't tick all of the timers in a single system. Maybe that's okay?
Closing as a duplicate of #15129; we should consolidate discussion there.
What problem does this solve or what need does it fill?
Performing a gameplay action after a specific amount of time has elapsed is a common and simple pattern.
Right now, this kind of sucks, because you need to make custom systems, components and tick timers for each effect (or build your own abstraction).
What solution would you like?
Add a
TimedCommand
helper inbevy_time
.These would be stored as a
Vec
in aTimedCommands
resource, and then all of the commands ticked (probably inFirst
?) during a system.Proposed by @cart on Discord.
What alternative(s) have you considered?
We could cannibalize
bevy_animation
's system for animation events, but that requires a weird dependency and isn't designed for this.Additional context
This was prompted by my review of https://github.com/bevyengine/bevy/pull/16440 :)