Hello fellow devs!
As the title says - calling a global event via SendEvent() from an action's OnExit() function will cause the event to be ignored and the FSM will still transition to whatever state it was transitioning regardless of the event.
To illustrate the issue, picture an FSM like this:
All states are empty except the one selected, and RESET_TEST, START_TEST and EVENT_SUCCESS events are global.
The PM_TransitionTest action is like this:
namespace HutongGames.PlayMaker.Actions
{
public class PM_TransitionTest : FsmStateAction
{
public override void OnExit()
{
PlayMakerFSM cFSM = Owner.gameObject.GetComponent<PlayMakerFSM>();
cFSM.SendEvent( "EVENT_SUCCESS" );
}
}
}
The logic of the test is:
- Send START_TEST (via Inspector) to start the test.
- After 1 second in Test_Wait, will try to transition to 'Test_Fail'.
- As part of the transition, the OnExit() in PM_TransitionTest will execute, which will send the 'EVENT_SUCCESS' in an attempt to change the transition to 'Test_Success'
- The SendEvent() is ignored and the FSM still transitions to 'Test_Fail'.
This is quite unintuitive as one would expect the call to SendEvent() to be honored and have an effect.
Can this be fixed, please?
Thanks for your time!