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
SystemName
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 queue of
Command
sA list of commands that will be run to modify an entity.
A function system that runs with exclusive
World
access.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
System
created by piping the output of the first system into the input of the second.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
.Name of the system that corresponds to this
crate::system::SystemState
.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
.A trait implemented for all exclusive system functions that can be used as
System
s.The state of a
SystemParam
.An extension trait providing the
IntoPipeSystem::pipe
method to pass input from one system into the next.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 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