#seldon-state, getting triggering entity

2 messages · Page 1 of 1 (latest)

covert whale
#

Hey @river torrent! Thanks for a cool state system, really enjoy the code ❤️🙏
I have a scenario that I can’t figure out though, if I have two entities using the same state_machine, but only one is responsible for the trigger, how would I go about retrieving that entity?
The scenario is, I have two pressure plates (left,right) and two boxes (left, right), when the left box is on the left plate, I fire a trigger that moves it to a state, when that happens, I want to mutate the left plate

river torrent
#

I'd recommend using command_on_enter, capturing the Entity in the command's closure:

let plate_entity: Entity = // ...
commands.spawn((
    // ...
    StateMachine::default()
        // ...
        .command_on_enter::<MyState>(move |world: &mut World| {
            let mut plate = world.get_mut::<Plate>(plate_entity);
            // ...
        }),
));