bevy::ecs::prelude

Trait System

source
pub trait System:
    Send
    + Sync
    + 'static {
    type In: SystemInput;
    type Out;

Show 19 methods // Required methods fn name(&self) -> Cow<'static, str>; fn component_access(&self) -> &Access<ComponentId>; fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>; fn is_send(&self) -> bool; fn is_exclusive(&self) -> bool; fn has_deferred(&self) -> bool; unsafe fn run_unsafe( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: UnsafeWorldCell<'_>, ) -> Self::Out; fn apply_deferred(&mut self, world: &mut World); fn queue_deferred(&mut self, world: DeferredWorld<'_>); unsafe fn validate_param_unsafe( &mut self, world: UnsafeWorldCell<'_>, ) -> bool; fn initialize(&mut self, _world: &mut World); fn update_archetype_component_access(&mut self, world: UnsafeWorldCell<'_>); fn check_change_tick(&mut self, change_tick: Tick); fn get_last_run(&self) -> Tick; fn set_last_run(&mut self, last_run: Tick); // Provided methods fn type_id(&self) -> TypeId { ... } fn run( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: &mut World, ) -> Self::Out { ... } fn validate_param(&mut self, world: &World) -> bool { ... } fn default_system_sets(&self) -> Vec<Interned<dyn SystemSet>> { ... }
}
Expand description

An ECS system that can be added to a Schedule

Systems are functions with all arguments implementing SystemParam.

Systems are added to an application using App::add_systems(Update, my_system) or similar methods, and will generally run once per pass of the main loop.

Systems are executed in parallel, in opportunistic order; data access is managed automatically. It’s possible to specify explicit execution order between specific systems, see IntoSystemConfigs.

Required Associated Types§

source

type In: SystemInput

The system’s input.

source

type Out

The system’s output.

Required Methods§

source

fn name(&self) -> Cow<'static, str>

Returns the system’s name.

source

fn component_access(&self) -> &Access<ComponentId>

Returns the system’s component Access.

source

fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>

Returns the system’s archetype component Access.

source

fn is_send(&self) -> bool

Returns true if the system is Send.

source

fn is_exclusive(&self) -> bool

Returns true if the system must be run exclusively.

source

fn has_deferred(&self) -> bool

Returns true if system has deferred buffers.

source

unsafe fn run_unsafe( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: UnsafeWorldCell<'_>, ) -> Self::Out

Runs the system with the given input in the world. Unlike System::run, this function can be called in parallel with other systems and may break Rust’s aliasing rules if used incorrectly, making it unsafe to call.

Unlike System::run, this will not apply deferred parameters, which must be independently applied by calling System::apply_deferred at later point in time.

§Safety
source

fn apply_deferred(&mut self, world: &mut World)

Applies any Deferred system parameters (or other system buffers) of this system to the world.

This is where Commands get applied.

source

fn queue_deferred(&mut self, world: DeferredWorld<'_>)

Enqueues any Deferred system parameters (or other system buffers) of this system into the world’s command buffer.

source

unsafe fn validate_param_unsafe(&mut self, world: UnsafeWorldCell<'_>) -> bool

Validates that all parameters can be acquired and that system can run without panic. Built-in executors use this to prevent invalid systems from running.

However calling and respecting System::validate_param_unsafe or it’s safe variant is not a strict requirement, both System::run and System::run_unsafe should provide their own safety mechanism to prevent undefined behavior.

This method has to be called directly before System::run_unsafe with no other (relevant) world mutations in between. Otherwise, while it won’t lead to any undefined behavior, the validity of the param may change.

§Safety
source

fn initialize(&mut self, _world: &mut World)

Initialize the system.

source

fn update_archetype_component_access(&mut self, world: UnsafeWorldCell<'_>)

Update the system’s archetype component Access.

§Note for implementors

world may only be used to access metadata. This can be done in safe code via functions such as UnsafeWorldCell::archetypes.

source

fn check_change_tick(&mut self, change_tick: Tick)

Checks any Ticks stored on this system and wraps their value if they get too old.

This method must be called periodically to ensure that change detection behaves correctly. When using bevy’s default configuration, this will be called for you as needed.

source

fn get_last_run(&self) -> Tick

Gets the tick indicating the last time this system ran.

source

fn set_last_run(&mut self, last_run: Tick)

Overwrites the tick indicating the last time this system ran.

§Warning

This is a complex and error-prone operation, that can have unexpected consequences on any system relying on this code. However, it can be an essential escape hatch when, for example, you are trying to synchronize representations using change detection and need to avoid infinite recursion.

Provided Methods§

source

fn type_id(&self) -> TypeId

Returns the TypeId of the underlying system type.

source

fn run( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: &mut World, ) -> Self::Out

Runs the system with the given input in the world.

For read-only systems, see run_readonly, which can be called using &World.

Unlike System::run_unsafe, this will apply deferred parameters immediately.

source

fn validate_param(&mut self, world: &World) -> bool

Safe version of System::validate_param_unsafe. that runs on exclusive, single-threaded world pointer.

source

fn default_system_sets(&self) -> Vec<Interned<dyn SystemSet>>

Returns the system’s default system sets.

Each system will create a default system set that contains the system.

Trait Implementations§

source§

impl<In, Out> Debug for dyn System<Out = Out, In = In>
where In: SystemInput + 'static, Out: 'static,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl IntoSystemConfigs<()> for Box<dyn System<Out = (), In = ()>>

source§

fn into_configs(self) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Convert into a SystemConfigs.
source§

fn in_set( self, set: impl SystemSet, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Add these systems to the provided set.
source§

fn before<M>( self, set: impl IntoSystemSet<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Runs before all systems in set. If self has any systems that produce Commands or other Deferred operations, all systems in set will see their effect. Read more
source§

fn after<M>( self, set: impl IntoSystemSet<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Run after all systems in set. If set has any systems that produce Commands or other Deferred operations, all systems in self will see their effect. Read more
source§

fn before_ignore_deferred<M>( self, set: impl IntoSystemSet<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Run before all systems in set. Read more
source§

fn after_ignore_deferred<M>( self, set: impl IntoSystemSet<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Run after all systems in set. Read more
source§

fn distributive_run_if<M>( self, condition: impl Condition<M> + Clone, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Add a run condition to each contained system. Read more
source§

fn run_if<M>( self, condition: impl Condition<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Run the systems only if the Condition is true. Read more
source§

fn ambiguous_with<M>( self, set: impl IntoSystemSet<M>, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Suppress warnings and errors that would result from these systems having ambiguities (conflicting access but indeterminate order) with systems in set.
source§

fn ambiguous_with_all(self) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Suppress warnings and errors that would result from these systems having ambiguities (conflicting access but indeterminate order) with any other system.
source§

fn chain(self) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Treat this collection as a sequence of systems. Read more
source§

fn chain_ignore_deferred( self, ) -> NodeConfigs<Box<dyn System<Out = (), In = ()>>>

Treat this collection as a sequence of systems. Read more

Implementors§

source§

impl<A, B> System for PipeSystem<A, B>
where A: System, B: System, <B as System>::In: for<'a> SystemInput<Inner<'a> = <A as System>::Out>,

source§

type In = <A as System>::In

source§

type Out = <B as System>::Out

source§

impl<A, B, Func> System for CombinatorSystem<Func, A, B>
where Func: Combine<A, B> + 'static, A: System, B: System,

source§

type In = <Func as Combine<A, B>>::In

source§

type Out = <Func as Combine<A, B>>::Out

source§

impl<Func, S> System for AdapterSystem<Func, S>
where Func: Adapt<S>, S: System,

source§

type In = <Func as Adapt<S>>::In

source§

type Out = <Func as Adapt<S>>::Out

source§

impl<Marker, F> System for ExclusiveFunctionSystem<Marker, F>
where Marker: 'static, F: ExclusiveSystemParamFunction<Marker>,

source§

impl<Marker, F> System for FunctionSystem<Marker, F>
where Marker: 'static, F: SystemParamFunction<Marker>,

source§

type In = <F as SystemParamFunction<Marker>>::In

source§

type Out = <F as SystemParamFunction<Marker>>::Out