playMaker

Author Topic: OnExit called when enabling FSM second time  (Read 2554 times)

turkeypotpie

  • Playmaker Newbie
  • *
  • Posts: 22
OnExit called when enabling FSM second time
« on: May 17, 2014, 08:30:47 PM »
I'm seeing the following strange behavior:

1.  I have an fsm attached to my GameObject.  It is initially disabled when the program starts.  'Reset on Disable' is set to true.  I have a custom FsmStateAction on one of my states with 'OnEnter' and 'OnExit' overridden.

2.  After the program starts I enable my fsm.  OnEnter is called.

3.  Later, I disable my fsm.  OnExit is called.

4.  Still later, I enable my fsm again.  OnExit is called a second time, and then OnEnter is called.

So why is OnExit being called again in Step #4?  It really messes up my game logic.  Is there any good way to detect whether the call is happening the second time so I can filter it out?

Btw, my fsm is basically a subfsm within a larger state machine.  It's enabled / disabled with the EnableFSM action.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: OnExit called when enabling FSM second time
« Reply #1 on: May 18, 2014, 12:04:08 PM »
I'll see if I can repro this here...

turkeypotpie

  • Playmaker Newbie
  • *
  • Posts: 22
Re: OnExit called when enabling FSM second time
« Reply #2 on: May 18, 2014, 02:03:58 PM »
Cool.  Thank you.

For me, it shows up with PlayMaker 1.7.7.1 on Unity 4.3.4, using a clean project.
« Last Edit: May 18, 2014, 02:07:58 PM by turkeypotpie »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: OnExit called when enabling FSM second time
« Reply #3 on: May 18, 2014, 07:14:33 PM »
Hi, I can confirm this is a bug  :(

The workaround until we fix this is to add a little extra logic to your action so OnExit checks if the action was entered:

Code: [Select]
public class ActionLifeCycleFix : FsmStateAction
{
    private bool entered;

    public override void OnEnter()
    {
        entered = true;
        ...
    }

    public override void OnExit()
    {
        if (!entered) return;
        ...
        entered = false;
    }
}

Only a few of the built in actions use OnExit and in those cases it doesn't matter if it's called twice, so it took a while to catch this bug - sorry!

This will be fixed in the next update, and we've added it to our automated tests now, so it shouldn't break again... thanks for your patience  :-\

turkeypotpie

  • Playmaker Newbie
  • *
  • Posts: 22
Re: OnExit called when enabling FSM second time
« Reply #4 on: May 19, 2014, 12:35:21 AM »
Cool.  Thanks for the fix on this ... and the workaround too. :)

Grhyll

  • Playmaker Newbie
  • *
  • Posts: 2
Re: OnExit called when enabling FSM second time
« Reply #5 on: April 01, 2015, 05:40:29 AM »
Hi,

I'm still seeing this issue in version 1.7.8, is this supposed to be fixed?

Thanks.

Grhyll

  • Playmaker Newbie
  • *
  • Posts: 2
Re: OnExit called when enabling FSM second time
« Reply #6 on: April 03, 2015, 08:14:06 AM »
Bump? (Despite the date, it wasn't an April fool.)