Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Mayhem on December 12, 2013, 03:10:52 PM

Title: How to Pause/Resume a FSM or a State
Post by: Mayhem on December 12, 2013, 03:10:52 PM
Hey there!

So I'm working with the cool Time Control and Pausekit in order to pause my game without TimeScale. It works pretty well. The only thing is: some certain fsms are still running, like the AI.

My AI is driven with the 2D Platform Controller-Plugin AND PlayMaker. The thing is I'm telling the AI via PlayMaker how exactly it should move. I made a simple EnemyInput-Script with certain functions like:

Code: [Select]
void MoveRight()
    {
        x = (0.5f*speed)*timeController.ControllerSpeedZeroToOne;
        moveDirection = 1;
    }


    /// <summary>
    /// Moves to Left
    /// </summary>
    void MoveLeft()
    {
        x = -0.5f*speed*timeController.ControllerSpeedZeroToOne;
        moveDirection = -1;
    }

I use the "Invoke Method"-action and call these methods. For example, the Patrol-State:

- MoveRight is called
-> AI walks to right
- Wait-Action for 1-2 seconds (Invoke also Method to stop movement!)
- MoveLeft is called
-> AI walks to left
and so on

When I pause the game, the AI stands still, but the state-machine is still working and changes it's states.

Is there a way to Pause the entire FSM in the certain state and when resumed it starts working again at that state?
Title: Re: How to Pause/Resume a FSM or a State
Post by: jeanfabre on December 14, 2013, 01:23:20 PM
Hi,

 I am not aware of any specific implementation for that.

bye,

 Jean
Title: Re: How to Pause/Resume a FSM or a State
Post by: Mayhem on December 14, 2013, 04:17:16 PM
Hm, that's bad.

Would it possible to do something like this:

- When the game is paused the Pause-Bool is set and a Global "Pause"-Event is fired and BroadCast to all objects in the scene.
- The Pause-Event is just a state which checks everyframe if the game is paused or not
- if the game is unpaused I use the "Goto Previous State"-Action and go to the action again which was active before pausing the game?
Title: Re: How to Pause/Resume a FSM or a State
Post by: Lane on December 14, 2013, 06:23:32 PM
That would probably end badly, if you could get it to work.
Title: Re: How to Pause/Resume a FSM or a State
Post by: Mayhem on December 14, 2013, 06:40:09 PM
Yeah, it would, probably...hm, any ideas or other suggestions?
Title: Re: How to Pause/Resume a FSM or a State
Post by: Lane on December 14, 2013, 07:58:07 PM
If AI is the only outstanding issue then you might be able to hop out with a global event and re enter with previous state, but the AI states would need to be setup so that re-entering the state wouldn't break them or create artifacts. I'm worried about interrupting them in some state and making redundant data or stacking up some sort of calculation by accidentally when you return and run the state twice.

Shouldn't really be too hard to test if you have a few agents, especially since the only thing you need to do is add the global event and a state with the action, pretty small footprint. I guess the case where it would break has a pretty small likelyhood of happening. Maybe it'll work.
Title: Re: How to Pause/Resume a FSM or a State
Post by: play_edu on October 09, 2014, 08:48:52 AM
Hi,

Any solution or any Update for Resume and pause FSM.i Have same Issue For my projects.

please help.
Title: Re: How to Pause/Resume a FSM or a State
Post by: Lane on October 09, 2014, 08:56:38 AM
A global Pause state is the way I would go.
Title: Re: How to Pause/Resume a FSM or a State
Post by: play_edu on October 10, 2014, 02:37:46 AM
Hi, Thanks for ans.

"Reset on Disable" is Working for me.