Bevy Sequential Actions
A Bevy library that aims to execute a queue of various actions in a sequential manner. This generally means that one action runs at a time, and when it is done, the next action will start and so on until the queue is empty.
Getting Started
Plugin
In order for everything to work, the SequentialActionsPlugin
must be added to your App
.
use *;
use *;
Modifying Actions
An action is anything that implements the Action
trait, and can be added to any Entity
that contains the ActionsBundle
.
An entity with actions is referred to as an agent
. See the ModifyActions
trait for available methods.
Implementing an Action
The Action
trait contains two methods:
- The
on_start
method which is called when an action is started. - The
on_stop
method which is called when an action is stopped.
In order for the action queue to advance, every action has to somehow signal when they are finished. There are two ways of doing this:
- Using the
ActionFinished
component on anagent
. By default, a system at the end of the frame will advance the queue if all active actions are finished. This is the typical approach as it composes well with other actions running in parallel. - Calling the
next
method on anagent
. This simply advances the queue at the end of the current stage it was called in. Useful for short one-at-a-time actions.
A simple wait action follows.
;
Warning
One thing to keep in mind is that you should not modify actions using World
inside the Action
trait.
We cannot borrow a mutable action from an agent
while also passing a mutable world to it.
Since an action is detached from an agent
when the trait methods are called,
the logic for advancing the action queue will not work properly.
This is why ActionCommands
was created, so you can modify actions inside the Action
trait in a deferred way.
;
Examples
See the examples for more usage, specifically the shared actions.
Each example can be run with cargo run --example <example>
.
Consider running with --release
as debug builds can be quite slow.
Example | Description |
---|---|
basic |
Shows the basic usage of the library by adding some actions and then quitting the app. |
pause |
Shows how to pause and resume an action when pressing space . |
repeat |
Shows how to add actions that repeat n times and forever. |
parallel |
Shows how to add a collection of actions that run in parallel. |
moba |
Shows how actions can be used to control a unit. Right click for movement, hold down left shift for queueing movements and press space for canceling everything. |
Compatibility
bevy | bevy-sequential-actions |
---|---|
0.10 | 0.7 |
0.9 | 0.6 |
0.8 | 0.3 — 0.5 |
0.7 | 0.1 — 0.2 |