Skip to main content

System

Trait System 

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

Show 17 methods // Required methods fn name(&self) -> DebugName; fn flags(&self) -> SystemStateFlags; unsafe fn run_unsafe( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: UnsafeWorldCell<'_>, ) -> Result<Self::Out, RunSystemError>; fn apply_deferred(&mut self, world: &mut World); fn queue_deferred(&mut self, world: DeferredWorld<'_>); fn initialize(&mut self, _world: &mut World) -> FilteredAccessSet; fn check_change_tick(&mut self, check: CheckChangeTicks); fn get_last_run(&self) -> Tick; fn set_last_run(&mut self, last_run: Tick); // Provided methods fn system_type(&self) -> TypeId { ... } fn type_id(&self) -> TypeId { ... } fn is_send(&self) -> bool { ... } fn is_exclusive(&self) -> bool { ... } fn has_deferred(&self) -> bool { ... } fn run( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: &mut World, ) -> Result<Self::Out, RunSystemError> { ... } fn run_without_applying_deferred( &mut self, input: <Self::In as SystemInput>::Inner<'_>, world: &mut World, ) -> Result<Self::Out, RunSystemError> { ... } 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 IntoScheduleConfigs.

Required Associated Types§

type In: SystemInput

The system’s input.

type Out

The system’s output.

Required Methods§

fn name(&self) -> DebugName

Returns the system’s name.

fn flags(&self) -> SystemStateFlags

Returns the SystemStateFlags of the system.

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

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

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.

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.

fn initialize(&mut self, _world: &mut World) -> FilteredAccessSet

Initialize the system.

Returns a FilteredAccessSet with the access required to run the system.

fn check_change_tick(&mut self, check: CheckChangeTicks)

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.

fn get_last_run(&self) -> Tick

Gets the tick indicating the last time this system ran.

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§

fn system_type(&self) -> TypeId

Returns the TypeId of the underlying system type.

fn type_id(&self) -> TypeId

👎Deprecated since 0.19.0:

Use system_type instead. This method shadows Any::type_id and will be removed in a future release.

Returns the TypeId of the underlying system type.

Use system_type instead.

fn is_send(&self) -> bool

Returns true if the system is Send.

fn is_exclusive(&self) -> bool

Returns true if the system must be run exclusively.

fn has_deferred(&self) -> bool

Returns true if system has deferred buffers.

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

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.

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

Runs the system with the given input in the world.

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§

§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

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

Convert into a ScheduleConfigs.
§

fn in_set(self, set: impl SystemSet) -> ScheduleConfigs<T>

Add these systems to the provided set.
§

fn before<M>(self, set: impl IntoSystemSet<M>) -> ScheduleConfigs<T>

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
§

fn after<M>(self, set: impl IntoSystemSet<M>) -> ScheduleConfigs<T>

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
§

fn before_ignore_deferred<M>( self, set: impl IntoSystemSet<M>, ) -> ScheduleConfigs<T>

Run before all systems in set. Read more
§

fn after_ignore_deferred<M>( self, set: impl IntoSystemSet<M>, ) -> ScheduleConfigs<T>

Run after all systems in set. Read more
§

fn distributive_run_if<M>( self, condition: impl SystemCondition<M> + Clone, ) -> ScheduleConfigs<T>

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

fn run_if<M>(self, condition: impl SystemCondition<M>) -> ScheduleConfigs<T>

Run the systems only if the SystemCondition is true. Read more
§

fn ambiguous_with<M>(self, set: impl IntoSystemSet<M>) -> ScheduleConfigs<T>

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

fn ambiguous_with_all(self) -> ScheduleConfigs<T>

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

fn chain(self) -> ScheduleConfigs<T>

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

fn chain_ignore_deferred(self) -> ScheduleConfigs<T>

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

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

§

type Metadata = GraphInfo

Additional data used to configure independent scheduling. Stored in ScheduleConfig.
§

type GroupMetadata = Chain

Additional data used to configure a schedulable group. Stored in ScheduleConfigs.
§

fn into_config(self) -> ScheduleConfig<Box<dyn System<Out = (), In = ()>>>

Initializes a configuration from this node.

Implementors§

§

impl System for ConditionWithAccess

§

type In = ()

§

type Out = bool

§

impl System for SystemWithAccess

§

type In = ()

§

type Out = ()

§

impl System for ApplyDeferred

§

type In = ()

§

type Out = ()

§

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>,

§

type In = <A as System>::In

§

type Out = <B as System>::Out

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<Marker, In, Out, F> System for FunctionSystem<Marker, In, Out, F>
where Marker: 'static, In: SystemInput + 'static, Out: 'static, F: SystemParamFunction<Marker>, <F as SystemParamFunction<Marker>>::In: FromInput<In>, <F as SystemParamFunction<Marker>>::Out: IntoResult<Out>,

§

type In = In

§

type Out = Out

§

impl<Marker, In, Out, Func, Builder> System for BuilderSystem<Marker, In, Out, Func, Builder>
where Marker: 'static, In: SystemInput + 'static, Out: 'static, Func: SystemParamFunction<Marker>, <Func as SystemParamFunction<Marker>>::In: FromInput<In>, <Func as SystemParamFunction<Marker>>::Out: IntoResult<Out>, Builder: SystemParamBuilder<<Func as SystemParamFunction<Marker>>::Param> + Send + Sync + 'static,

§

type In = In

§

type Out = Out

§

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

§

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

§

type Out = Out

§

impl<S, T> System for WithInputFromWrapper<S, T>
where S: for<'i> System, <S as System>::In: for<'i> SystemInput<Inner<'i> = &'i mut T>, T: FromWorld + Send + Sync + 'static,

§

type In = ()

§

type Out = <S as System>::Out

§

impl<S, T> System for WithInputWrapper<S, T>
where S: for<'i> System, <S as System>::In: for<'i> SystemInput<Inner<'i> = &'i mut T>, T: Send + Sync + 'static,

§

type In = ()

§

type Out = <S as System>::Out