bevy_ecs::system

Trait System

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

Show 17 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, world: UnsafeWorldCell<'_>, ) -> Self::Out; fn apply_deferred(&mut self, world: &mut World); fn queue_deferred(&mut self, world: DeferredWorld<'_>); 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, world: &mut World) -> Self::Out { ... } fn default_system_sets(&self) -> Vec<InternedSystemSet> { ... }
}
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

The system’s input. See In for FunctionSystems.

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 as deferred buffers

Source

unsafe fn run_unsafe( &mut self, input: Self::In, 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
  • The caller must ensure that world has permission to access any world data registered in Self::archetype_component_access. There must be no conflicting simultaneous accesses while the system is running.
  • The method Self::update_archetype_component_access must be called at some point before this one, with the same exact World. If update_archetype_component_access panics (or otherwise does not return for any reason), this method must not be called.
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

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, 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 default_system_sets(&self) -> Vec<InternedSystemSet>

Returns the system’s default system sets.

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

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Implementors§

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