Expand description
Tools for controlling behavior in an ECS application.
Systems define how an ECS based application behaves. They have to be registered to a
SystemStage
to be able to run. A system is usually
written as a normal function that will be automatically converted into a system.
System functions can have parameters, through which one can query and mutate Bevy ECS state.
Only types that implement SystemParam
can be used, automatically fetching data from
the World
.
System functions often look like this:
fn update_score_system(
mut query: Query<(&Player, &mut Score)>,
mut round: ResMut<Round>,
) {
for (player, mut score) in &mut query {
if player.alive {
score.0 += round.0;
}
}
round.0 += 1;
}
System ordering
While the execution of systems is usually parallel and not deterministic, there are two ways to determine a certain degree of execution order:
- System Stages: They determine hard execution synchronization boundaries inside of which systems run in parallel by default.
- Labeling: First, systems are labeled upon creation by calling
.label()
. Then, methods such as.before()
and.after()
are appended to systems to determine execution order in respect to other systems.
System parameter list
Following is the complete list of accepted types as system parameters:
Query
Res
andOption<Res>
ResMut
andOption<ResMut>
Commands
Local
EventReader
EventWriter
NonSend
andOption<NonSend>
NonSendMut
andOption<NonSendMut>
&World
RemovedComponents
SystemChangeTick
Archetypes
(Provides Archetype metadata)Bundles
(Provides Bundles metadata)Components
(Provides Components metadata)Entities
(Provides Entities metadata)- All tuples between 1 to 16 elements where each element implements
SystemParam
()
(unit primitive type)
Modules
Structs
A System
that chains two systems together, creating a new system that routes the output of
the first system into the input of the second system, yielding the output of the second system.
A queue of Command
s
A queue of commands that get executed at the end of the stage of the system that called them.
A list of commands that will be run to modify an entity.
The System
counter part of an ordinary function.
Wrapper type to mark a SystemParam
as an input.
A system local SystemParam
.
Command
to log the components of a given entity. See EntityCommands::log_components
.
Unique borrow of a non-Send
resource.
An alternative to Commands
that can be used in parallel contexts, such as those in Query::par_for_each
A SystemParam
that grants access to the entities that had their T
Component
removed.
Shared borrow of a resource.
Unique mutable borrow of a resource.
A helper for using system parameters in generic contexts
A SystemParam
that reads the previous and current change ticks of the system.
The metadata of a System
.
Holds on to persistent state required to drive SystemParam
for a System
.
A SystemLabel
that was automatically generated for a system on the basis of its TypeId
.
Enums
Traits
Used to implicitly convert systems to their default labels. For example, it will convert
“system functions” to their SystemTypeIdLabel
.
An extension trait providing the IntoChainSystem::chain
method for convenient System
chaining.
Conversion trait to turn something into a System
.
A SystemParamFetch
that only reads a given World
.
A parameter that can be used in a System
.
A trait implemented for all functions that can be used as System
s.
The state of a SystemParam
.
Functions
Ensure that a given function is an exclusive system
Ensure that a given function is a system
Type Definitions
A convenience type alias for a boxed System
trait object.
Derive Macros
Implement SystemParam
to use a struct as a parameter in a system