Module bevy::ecs::system

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:

Modules

Structs

A Command queue to perform impactful changes to the World.
A 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.
Shared borrow of a non-Send resource.
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.
System parameter that provides selective access to the Component data stored in a World.
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.
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

An error that occurs when retrieving a specific Entity’s component from a Query

Traits

Used to implicitly convert systems to their default labels. For example, it will convert “system functions” to their SystemTypeIdLabel.
A World mutation.
A trait implemented for all exclusive system functions that can be used as Systems.
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 type that can be inserted into a World as a singleton.
An ECS system that can be added to a Schedule
A parameter that can be used in a System.
A trait implemented for all functions that can be used as Systems.

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