pub trait System: Send + Sync + 'static {
type In;
type Out;
Show 15 methods
// Required methods
fn name(&self) -> Cow<'static, str>;
fn type_id(&self) -> TypeId;
fn component_access(&self) -> &Access<ComponentId>;
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>;
fn is_send(&self) -> bool;
fn is_exclusive(&self) -> bool;
unsafe fn run_unsafe(
&mut self,
input: Self::In,
world: UnsafeWorldCell<'_>
) -> Self::Out;
fn apply_deferred(&mut self, world: &mut World);
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 run(&mut self, input: Self::In, world: &mut World) -> Self::Out { ... }
fn default_system_sets(&self) -> Vec<Box<dyn SystemSet, Global>, Global> { ... }
}
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§
type In
type In
The system’s input. See In
for
FunctionSystem
s.
type Out
type Out
The system’s output.
Required Methods§
fn component_access(&self) -> &Access<ComponentId>
fn component_access(&self) -> &Access<ComponentId>
Returns the system’s component Access
.
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>
fn archetype_component_access(&self) -> &Access<ArchetypeComponentId>
Returns the system’s archetype component Access
.
fn is_exclusive(&self) -> bool
fn is_exclusive(&self) -> bool
Returns true if the system must be run exclusively.
unsafe fn run_unsafe(
&mut self,
input: Self::In,
world: UnsafeWorldCell<'_>
) -> Self::Out
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.
Safety
- The caller must ensure that
world
has permission to access any world data registered inSelf::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 exactWorld
. Ifupdate_archetype_component_access
panics (or otherwise does not return for any reason), this method must not be called.
fn apply_deferred(&mut self, world: &mut World)
fn apply_deferred(&mut self, world: &mut World)
fn initialize(&mut self, _world: &mut World)
fn initialize(&mut self, _world: &mut World)
Initialize the system.
fn update_archetype_component_access(&mut self, world: UnsafeWorldCell<'_>)
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
.
fn check_change_tick(&mut self, change_tick: Tick)
fn check_change_tick(&mut self, change_tick: Tick)
Checks any Tick
s 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
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)
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 run(&mut self, input: Self::In, world: &mut World) -> Self::Out
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
.
fn default_system_sets(&self) -> Vec<Box<dyn SystemSet, Global>, Global>
fn default_system_sets(&self) -> Vec<Box<dyn SystemSet, Global>, Global>
Returns the system’s default system sets.
Trait Implementations§
§impl IntoSystemConfigs<()> for Box<dyn System<Out = (), In = ()>, Global>
impl IntoSystemConfigs<()> for Box<dyn System<Out = (), In = ()>, Global>
§fn in_set(self, set: impl SystemSet) -> SystemConfigs
fn in_set(self, set: impl SystemSet) -> SystemConfigs
set
.§fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
fn before<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
set
.§fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
fn after<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
set
.§fn distributive_run_if<M>(
self,
condition: impl Condition<M, ()> + Clone
) -> SystemConfigs
fn distributive_run_if<M>( self, condition: impl Condition<M, ()> + Clone ) -> SystemConfigs
§fn run_if<M>(self, condition: impl Condition<M, ()>) -> SystemConfigs
fn run_if<M>(self, condition: impl Condition<M, ()>) -> SystemConfigs
§fn ambiguous_with<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
fn ambiguous_with<M>(self, set: impl IntoSystemSet<M>) -> SystemConfigs
set
.§fn ambiguous_with_all(self) -> SystemConfigs
fn ambiguous_with_all(self) -> SystemConfigs
§fn chain(self) -> SystemConfigs
fn chain(self) -> SystemConfigs
§fn on_startup(self) -> SystemConfigs
fn on_startup(self) -> SystemConfigs
app.add_system(foo.on_startup())
has been deprecated in favor of app.add_systems(Startup, foo)
. Please migrate to that API.CoreSchedule::Startup
.
This was a shorthand for self.in_schedule(CoreSchedule::Startup)
. Read more§fn in_schedule(self, _schedule: impl ScheduleLabel) -> SystemConfigs
fn in_schedule(self, _schedule: impl ScheduleLabel) -> SystemConfigs
app.add_system(foo.in_schedule(SomeSchedule))
has been deprecated in favor of app.add_systems(SomeSchedule, foo)
. Please migrate to that API.schedule
. Read more