Crate bevy_entity_system

Source
Expand description

This crate provides easy to use way to make systems that operate on a single entity.

§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.

§Example

#[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;
}

bevy_ecs::system::assert_is_system(my_entity_system.into_system());
bevy_ecs::system::assert_is_system(my_entity_system_with_input.into_system());

Modules§

data_match
Contains DataMatch
implementors
Built in implementations of EntitySystem
into_entity_system
Convenience in working with EntitySystems
into_system
Implementation of IntoSystem
marked_entity_system
Contains functionality to run EntitySystems that should be marked in order to implement this trait This is necessary to avoid conflicting implementations when implementing trait for rust functions
prelude
Prelude module

Traits§

EntitySystem
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
ReadOnlyEntitySystem
Implemented for EntitySystems that only read data from the world