Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: ciabaros on April 13, 2013, 01:27:10 PM
-
Problem Setup:
- A regular FSM (not SubFSM) is configured to NOT "Reset on Disable" in inspector (by design, I need it to sometime continue after re-enable).
- Once it reaches a certain state, it calls "FinishFSM", and gets put into "Fsm.Finished" state and disabled.
Without enabling the "Reset on Disable" feature, I need to manually restart this FSM (via code, from another FSM). I tried PlayMakerFSM.Reset( ) and Fsm.Reset( <component> ), and both just reset the FSM structure itself (by clearing the component's data), to the default 1-state FSM.
I Tried:
- Fsm.Init( )
- Fsm.Reinitialize( )
- PlayMakerFSM.Reset( ) and Fsm.Reset( * ) as mentioned above.
Of course, I'm explicitly enabling it first.. all works if the "Reset on Disable" flag is enabled on this FSM component, but I need to do the same action that this flag initiates in the backend, in my custom Action code.. Help :)
-
Not at my computer to check, but try Fsm.Start();
-
Sorry I didn't explicitly mention, I was running Start( ) in every case. But I have since found a workaround:
It feels like some weird technicality, but it works!
It seems that the way you programatically "Reset" an FSM which does not "Reset on Disable", AND is Finished via FinishFSM ([fsmComponent].Fsm.Finished==true), is to:
- Temporarily enable its "[fsmComponent].Fsm.RestartOnEnable" flag
- Enable the FSM by "[fsmComponent].enabled = true"
- Stop the FSM by "[fsmComponent].Fsm.Stop( )"
- Start the FSM by "[fsmComponent].Fsm.Start( )"
- Restore the previous value for the "[fsmComponent].Fsm.RestartOnEnable" flag.
That was fun. Hope this saves anyone the hours it took me to figure out by trial and error.
Edit:
Only Fsm.Stop( ) cares about the RestartOnEnable flag. So enable can happen after the flag is reverted, and hence, the entire sure-resetting mechanism is just:
- Temporarily enable its "[fsmComponent].Fsm.RestartOnEnable" flag
- Stop the FSM by "[fsmComponent].Fsm.Stop( )"
- Restore the previous value for the "[fsmComponent].Fsm.RestartOnEnable" flag.