Open soanvig opened 1 week ago
Would it be sufficient in your use case to get the entity ID when spawning it?
let mut my_entity = commands.spawn_empty();
let my_entity_id = my_entity.id();
my_entity.insert(
StateMachine::default()
.trans_builder(MyTrigger, move |my_state: &MyState, another_entity| {
(my_entity != another_entity).then_some(MyOtherState)
})
);
Surely. Thanks for the workaround. It reduces flexibility (I cannot >easily< have state machine factory), but it works.
It would be nice to have access to an entity the state machine is assigned to in the
.trans_builder
.For example - I can react to an event, and switch a state, but only if the event corelates with the entity. The event carries over the information about the entity in one of its fields. The state machine however has access only to its current state, so unless I store the entity in the state, I cannot compare entity in the event, and entity that uses the state machine.
I think technically there is no reason to not provide an entity to the
.trans_builder
, am I right?I can help with a PR