Page 1 of 1
Time Transition interrupted and FSM resetについて
Posted: 2019/10/15 14:05
by CHOP_JZL
Hello!
Today I was trying the Example 1(Basic FSM). In the Time example, if I press "back" when the cube is active, although I went back to mainmenu, the Time FSM still counting. Then when I press "Time" again, the FSM back to work from last time it stoped. So the cube will be active at the begining and become inactive immediately, which is not what I want.
Can I reset a FSM(timer, children active, etc) when get interrupted? Like the "back" button in Example 1. I tried "stop state machine", although I can restart FSM, the states data is not reseted...
Re: Time Transition interrupted and FSM resetについて
Posted: 2019/10/16 00:02
by caitsithware
Example 1 (Basic FSM) is a simple example and does not implement complex reset processing.
To implement reset, it is better to implement reset state by combining SendTrigger, TriggerTransition, PlayStateMachine, StopStateMachine.
For example, the following FSM.
MainMenu
- Example_FSMReset_Time.png (124.62 KiB) Viewed 5733 times
Open
Time
- Example_FSMReset_Time.png (124.62 KiB) Viewed 5732 times
Open
Main flow
- MainMenu FSM : In the Time state, activate the Time object and play the TimeFSM.
- MainMenu FSM : When the Back button is pressed, a "Reset" trigger message is sent to TimeFSM in the ResetTimeFSM state.
- Time FSM : Accept the "Reset" trigger with ResetTrigger in the resident state, and immediately transition to the Reset state.
- Time FSM : Performs reset processing in the Reset state and immediately transitions to the End state.
- Time FSM : Send "End" trigger to MainMenu FSM in End state.
- MainMenu FSM : Reset TimeFSM accepts "End" trigger and immediately transitions to EndTimeFSM state.
- MainMenu FSM : Stop Time FSM and deactivate Time object in EndTimeFSM state. Transition to MainMenu state.
By using graph hierarchies (SubStateMachine, EndStateMachine), you can build the best graph.
See Example 14 (Graph Hierarchy) for more information on graph hierarchy.
Re: Time Transition interrupted and FSM resetについて
Posted: 2019/10/16 01:28
by CHOP_JZL
Hello!
Thank you for the answer. After I reproduce it myself, I noticed I made a big mistake. I used "stop state machine" after the Time gameobject is inactived, that's why the FSM didn't stop...In the mainmenu graph of your answer, I tried to just link "Time" node and "End TimeFSM" node, it still words, and the TimeFSM reseted properly. So the FSM actually can reset it self if it's active , my mistake...