playMaker

Author Topic: Need help resetting an FSM  (Read 982 times)

neonaleon

  • Playmaker Newbie
  • *
  • Posts: 2
Need help resetting an FSM
« on: May 17, 2019, 05:15:49 AM »
Hi, I was wondering if anyone had experience with a need to reset an FSM.

Example like this:
FSM is at State 10, but the player died, and I restart the level.
Upon restarting the level, I want the FSM to start from State 1, so I call SetState.
The FSM however Exits State 10 and Enters State 1, which I don't want.

I tried this, but the FSM remembers the last state, and actually still Exits State 10 and Enters State 1, when I call Start().
https://hutonggames.com/playmakerforum/index.php?topic=3646.0

Is there a way to Reset the FSM so that I can start the FSM as if it was the first time it started?

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: Need help resetting an FSM
« Reply #1 on: May 17, 2019, 05:54:09 AM »
"Upon restarting the level, I want the FSM to start from State 1, so I call SetState.
The FSM however Exits State 10 and Enters State 1, which I don't want."

Isn't it doing exactly what you want ?

Why don't you add a "PlayerDied" global event to your FSM , then you can chose for every state what happens when the player dies ?

For example at state 10 the player dies the event is broadcasted and leads the FSM to state 1 . If he dies at state 3 though a different behaviour can be triggered.

neonaleon

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Need help resetting an FSM
« Reply #2 on: May 17, 2019, 06:06:41 AM »
I don't want it to Exit State 10, but, instead start at State 1, as if the FSM was started the first time.

I could do that, but it would still Exit State 10.

The FSM remembers the PreviousActiveState, even after Stopping and RestartOnEnable.

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 219
Re: Need help resetting an FSM
« Reply #3 on: May 17, 2019, 11:44:12 AM »
I dont think you are restarting the level via the "Restart Level" action as this would force everything to start at state 1.

Regardless, as said before your next best option is to have something listen for "PlayerDied" and then send a global event like PLAYER_DIED to all objects (or just it).  On your FSM that you need to reset, find its start state, right click and pick the Global Event and select PLAYER_DIED.