You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a state calls fsm.StateCanExit while in its OnEnter method, the call seems to be ignored. The state will never exit. However, if the call is moved inside the OnLogic method, everything works as expected.
Not quite sure if this is intended behavior or not, thus labelling this as an issue for now.
If this indeed is intended behavior, I'd recommend adding a warning to the README and to fsm.StateCanExit XML docs about this.
Example script that showcases the behavior:
usingUnityEngine;usingUnityHFSM;namespaceUnityHFSMTest{publicclassTestState:StateBase{publicTestState():base(needsExitTime:true){}publicoverridevoidOnEnter(){Debug.Log("TestState.OnEnter");// Calling "fsm.StateCanExit" in OnEnter does not allow the state to exit.fsm.StateCanExit();Debug.Log("TestState.OnEnter: StateCanExit called");}publicoverridevoidOnLogic(){Debug.Log("TestState.OnLogic");}}/// <summary>/// This example demonstrates how the calling "StateCanExit" in OnEnter does not allow the state to exit./// </summary>publicclassUnityHFSMStateCanExitTest:MonoBehaviour{privateStateMachine_rootFsm;privatevoidAwake(){_rootFsm=newStateMachine();// ----- States -----_rootFsm.AddState("StateA",onEnter: _ =>{print("StateA.OnEnter");},onLogic: state =>{if(state.timer.Elapsed>1)state.fsm.StateCanExit();},needsExitTime:true);_rootFsm.AddState("TestState",newTestState());// ----- Transitions -----// Alternate between "state A" and "TestState"._rootFsm.AddTransition(newTransition("StateA","TestState"));_rootFsm.AddTransition(newTransition("TestState","StateA"));}privatevoidStart()=>_rootFsm.Init();privatevoidUpdate()=>_rootFsm.OnLogic();}}
Expected output:
The "TestState.OnLogic" debug line would NOT get printed.
Actual output:
The exit call is ignored.
Temporary fix:
If we move the fsm.StateCanExit() call to the OnLogic method, the state is exited as expected:
The text was updated successfully, but these errors were encountered:
When a state calls
fsm.StateCanExit
while in itsOnEnter
method, the call seems to be ignored. The state will never exit. However, if the call is moved inside theOnLogic
method, everything works as expected.Not quite sure if this is intended behavior or not, thus labelling this as an issue for now.
If this indeed is intended behavior, I'd recommend adding a warning to the README and to
fsm.StateCanExit
XML docs about this.Example script that showcases the behavior:
Expected output:
The "TestState.OnLogic" debug line would NOT get printed.
Actual output:
The exit call is ignored.
Temporary fix:
If we move the
fsm.StateCanExit()
call to theOnLogic
method, the state is exited as expected:The text was updated successfully, but these errors were encountered: