EntitySystem

Trait EntitySystem 

Source
pub trait EntitySystem:
    Send
    + Sync
    + 'static {
    type Data: QueryData;
    type Filter: QueryFilter;
    type Param: SystemParam;
    type In;
    type Out;

    // Required method
    fn run(
        &mut self,
        input: Self::In,
        data_value: QueryItem<'_, Self::Data>,
        param_value: SystemParamItem<'_, '_, Self::Param>,
    ) -> Self::Out;
}
Expand description

Trait implemented for all functions that can be used as Systems and operate on a single Entity. Such system can only be run for entities that match it’s Data and Filter

Every entity system that is function that has Data as a first (or second after In) parameter

#[derive(Component)]
struct Count(i32);
 
#[derive(Component)]
struct MyMarkerComponent;

fn my_entity_system(
    mut data: Data<&mut Count, With<MyMarkerComponent>>,
    mut commands: Commands
) {
    data.item.0 += 1;
    commands.spawn(Count(10));
}

fn my_entity_system_with_input(input: In<i32>, mut data: Data<&mut Count>) {
    data.item.0 += *input;
}
 

§Warning

Currently there is a bug, individual entity systems don’t store their state. State is being shared across all entities that are being iterated by the system that resulted from into_system call. That means that Local, EntityReader and other SystemParam’s, that rely on it’s state property to be preserved between system runs, won’t work correctly. It is a huge footgun, so the work on fixing it is being done.

After fix, the API will change, user would need to explicitly specify the entities this system is allowed to run on. That means, you most probably would need to be able to mutate systems at runtime - something that bevy currently doesn’t support. I also work on a crate that will be able to provide you with such functionality - it is not published yet.

§Custom implementation

If you have a custom implementation of the trait, it’s highly recommended to also derive IntoSystem trait

§Note

Since IntoSystem is defined in bevy_ecs crate, it’s impossible to implement it for the rust functions. Use into_system or into_system_with_output instead or convert to one of the type that implements such trait.

Required Associated Types§

Source

type Data: QueryData

QueryData to get from the world for the entity that system is run on

Source

type Filter: QueryFilter

Filtering of the entities that are allowed to be run on by this system

Source

type Param: SystemParam

SystemParam’s of the system

Source

type In

Input of the system

Source

type Out

Output of the system

Required Methods§

Source

fn run( &mut self, input: Self::In, data_value: QueryItem<'_, Self::Data>, param_value: SystemParamItem<'_, '_, Self::Param>, ) -> Self::Out

Executes this system once.

Implementors§

Source§

impl<A: EntitySystem, B: EntitySystem<In = A::Out>> EntitySystem for PipeEntitySystem<A, B>

Source§

type Data = Entity

Source§

type Filter = (DataMatch<<A as EntitySystem>::Data>, <A as EntitySystem>::Filter, DataMatch<<B as EntitySystem>::Data>, <B as EntitySystem>::Filter)

Source§

type Param = ParamSet<'static, 'static, ((Query<'static, 'static, <A as EntitySystem>::Data, (DataMatch<<A as EntitySystem>::Data>, <A as EntitySystem>::Filter, DataMatch<<B as EntitySystem>::Data>, <B as EntitySystem>::Filter)>, <A as EntitySystem>::Param), (Query<'static, 'static, <B as EntitySystem>::Data, (DataMatch<<A as EntitySystem>::Data>, <A as EntitySystem>::Filter, DataMatch<<B as EntitySystem>::Data>, <B as EntitySystem>::Filter)>, <B as EntitySystem>::Param))>

Source§

type In = <A as EntitySystem>::In

Source§

type Out = <B as EntitySystem>::Out

Source§

impl<Marker: 'static, T: MarkedEntitySystem<Marker>> EntitySystem for MarkedEntitySystemRunner<Marker, T>

Source§

type Data = <T as MarkedEntitySystem<Marker>>::Data

Source§

type Filter = <T as MarkedEntitySystem<Marker>>::Filter

Source§

type Param = <T as MarkedEntitySystem<Marker>>::Param

Source§

type In = <T as MarkedEntitySystem<Marker>>::In

Source§

type Out = <T as MarkedEntitySystem<Marker>>::Out

Source§

impl<T: EntitySystem> EntitySystem for OptionalEntitySystem<T>

Source§

impl<T: EntitySystem, Func: Adapt<T>> EntitySystem for AdapterEntitySystem<T, Func>

Source§

type Data = <T as EntitySystem>::Data

Source§

type Filter = <T as EntitySystem>::Filter

Source§

type Param = <T as EntitySystem>::Param

Source§

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

Source§

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