Trait amethyst::prelude::SystemExt[]

pub trait SystemExt {
    pub fn pausable<V>(self, value: V) -> Pausable<Self, V>
        V: 'static + Send + Sync + Default + PartialEq<V>
; }

Extension functionality associated systems.

Required methods

pub fn pausable<V>(self, value: V) -> Pausable<Self, V> where
    V: 'static + Send + Sync + Default + PartialEq<V>, 

Make a system pausable by tying it to a specific value of a resource.

When the value of the resource differs from value the system is considered "paused", and the run method of the pausable system will not be called.


Special care must be taken not to read from an EventChannel with pausable systems. Since run is never called, there is no way to consume the reader side of a channel, and it may grow indefinitely leaking memory while the system is paused.


use amethyst::{
    ecs::{System, Write},

enum CurrentState {

impl Default for CurrentState {
    fn default() -> Self {

struct AddNumber(u32);

impl<'s> System<'s> for AddNumber {
    type SystemData = Write<'s, u32>;

    fn run(&mut self, mut number: Self::SystemData) {
        *number += self.0;

let mut world = World::new();

let mut dispatcher = DispatcherBuilder::default()
    .with(AddNumber(1), "set_number", &[])
    .with(AddNumber(2).pausable(CurrentState::Enabled), "set_number_2", &[])

dispatcher.setup(&mut world);

// we only expect the u32 resource to be modified _if_ the system is enabled,
// the system should only be enabled on CurrentState::Enabled.

*world.write_resource() = 0u32;
dispatcher.dispatch(&mut world);
assert_eq!(1, *world.read_resource::<u32>());

*world.write_resource() = 0u32;
*world.write_resource() = CurrentState::Enabled;
dispatcher.dispatch(&mut world);
assert_eq!(1 + 2, *world.read_resource::<u32>());
Loading content...


impl<'s, S> SystemExt for S where
    S: System<'s>, 

Loading content...