Playmaker Forum

Playmaker Help & Tips => Playmaker Help => Topic started by: haikugames on June 30, 2015, 09:07:41 AM

Title: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on June 30, 2015, 09:07:41 AM
I have an adventure game made in Playmaker. In the game I have a lot of FSMs which represent objects the player can interact with.  For example, I have a Sprite with a PlaymakerFSM which is a box.  It starts unopened, and then when the player taps on it, I change the Sprite to a box open sprite with an item inside, and when the player taps again the item is taken.  My FSM represents each of these states.

Right now, we just save when the player has completed the entire scene (we just keep a Int in PlayerPrefs to note how many levels the player has completed). Ideally, we will save the progress of the player every time he takes an action, so if he does not complete the whole scene, he can return to it later.

My question is what's the best way to save all this.  I want the player to be able to load the level and see all the objects in the state s/he left them in (so if they opened the box but didn't take the item, it looks like that).  As far as I can tell, it's hard to load FSMs in an intermediate state. 

We're looking for advice here, but if someone knows how to do this we are also hiring a contractor to implement the system for our project:
https://www.upwork.com/jobs/Save-and-Restore-Intermediate-FSM-States-Playmaker_~017f41263674437436
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: djaydino on June 30, 2015, 09:37:02 AM
easy save 2 (asset not free) has a save all action witch saves all global variables and / or fsm variables
and an action to load all.

if used with only fsm variables it will save only the variables inside that fsm which can be useful

another way is maybe to use (free) ArrayMaker (https://hutonggames.fogbugz.com/default.asp?W715) or DataMaker (https://hutonggames.fogbugz.com/default.asp?W1133) (xml)
which can be easier to use when prefabs are used.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on June 30, 2015, 12:18:12 PM
Thanks for replying. I understand I can use EasySave to save all FSM variables, but that still won't let me restore the state I am in.  Let's say I have 3 states.

1) Box Unopened (start state), 2) Box Opened, 3) Item taken from box.

Let's say the player is in State #2.  If I use EasySave, I can save the variables of State #2.  However, when I load, Playmaker still thinks that I am in State 1 because that is the start state.  That's troublesome because I want the player to be able to tap and go from State #2 to State #3.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: jeanfabre on June 30, 2015, 12:27:48 PM
Hi,

There isn't any easy solution for this atm. But I guess there is a potential small system to create that could simply save the current state and force an fsm to enter that state on demand. I have created a system that is synchronized with Unity Mecanim states, so I guess I can work something out of this for that purpose.

 Can you bump me towards the end of the week if nothing comes up from me on this thread?

Bye,

 Jean
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on June 30, 2015, 01:29:58 PM
That sounds great. I can't say enough about Playmaker - it allowed us to create our entire project.  It's very baked into our project, so we just want to be able to go back and add save states.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: djaydino on June 30, 2015, 02:00:48 PM
the way you could do is make an int, set default 1. when box is opened set to 2, when item is taken set to 3 and save

on start state load the int before the other actions, then do an int switch
if 2 go to state 2 , 3 go to state 3

you can do this with playerprefs also
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on July 05, 2015, 10:03:37 PM
Hi Jean, I wanted to bump you about the possibility of some way to restore FSM states.

@djaydino, I thought of that as a strategy.  The reason I didn't want to go with that is if I have a FSM with 20 or 30 states, I will need to have 20 or 30 separate events to restore each state.  Since we have many FSMs in each scene, it seems like it will be an overwhelming amount of manual work which is very error prone.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: djaydino on July 06, 2015, 05:28:15 AM
Hi,
i do not know how you fsm's are setup,
but i think you do not need to connect to each state, only @ key points.

but it would ofc be easier if you could save all current states and get them back in on loading.

i might take a while (jean is a very busy man)

but keep on bumping.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on July 09, 2015, 06:33:07 PM
Thanks Dino :). 
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Thyriax on July 09, 2015, 11:47:45 PM
Hi,
Maybe, you could work with Array Maker and use "Array list send event to game object"?
Or use "Exists" action to compare a saved variable within a gameobjet?
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: jeanfabre on July 15, 2015, 09:39:31 AM
Hi,

 I am indeed interesting in this topic, so please bump me, get back to me end of august. I know that I won't be able to look at this before then, but I do want to do something for state restore, it's not difficult but needs to be done right.


Bye,

 Jean
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Nimred on July 26, 2015, 11:10:06 AM
Hi,

I just wanted to say that I have pretty much the same need as haikugames. My game uses lots of state machines to drive the story (one per narrative "scene") and when the player takes action and moves the story along, the state changes accordingly.

I need to be able to save which state the player is in, and restore to that state next time the game is started. I tried to set the ActiveState on the Fsm, but unfortunately that's not accessible.

I would also like to be able to set an FSM back to its starting state, without having to call enable/disable. Both problems could possibly be solved if the active state could be changed by script...

I hope you can find time for this soon :)

Michael
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on August 13, 2015, 04:18:03 PM
I wanted to bump this as we are in August now.   :)
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on August 28, 2015, 02:03:05 PM
Another bump :)

Nimred - if you found another solution let us know please! Thanks
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on September 05, 2015, 05:43:08 PM
Still very much interested in this :)
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Nimred on September 24, 2015, 02:50:43 AM
Hi there,

I actually took another look at the problem today and noticed that while the "ActiveState" of an FSM cannot be modified, the "StartState" can...

I did a quick test, and successfully jumped to a chosen state in Awake(), without going through the true start state.

Code: [Select]
myFSM.Fsm.StartState = "State 3";
In order to use this for real, I will just make some scripts to regularly save to a file the current states of all ingame FSMs, and possibly also global and local variables, which are also modifiable.

I'm glad there's a solution after all :)

Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: jeanfabre on September 24, 2015, 03:34:59 AM
Hi,

 I am waiting for 1.8 to go public so that I do one action that works always, else it would be tricky.

 Please bump me when 1.8 will be out ok? thanks for your patience :)

Bye,

 Jean
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on March 31, 2016, 12:12:25 AM
Hello, as 1.8 is in a very stable beta, I was wondering if it will be possible to create this action.  Thanks!
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: djaydino on March 31, 2016, 06:03:01 AM
Hi,
With "Easy save" you can save all and load all (local and Global)
BUT the problem is that it does not do this on "Awake"
and the actions are not editable.
I asked moodkie if he can add a 'on awake' option on his actions.

So for now i made a "PlayerPrefs Get String on Awake" Action
so you can load a string on awake and i made a "set Fsm Start State"
to set a fsm start state on awake. and this seems to work :)

i will add them on the EcoSystem after some more testing
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: shadowof047 on September 20, 2016, 01:47:54 PM
Bump ,

I'm also interested in this . an action which loads the fsm state would be great .
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: haikugames on June 01, 2017, 12:37:57 PM
I don't suppose there is any update to this :) We still want to save and load FSM states.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Alatriste on September 22, 2018, 10:45:27 AM
Any update on this?
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: jeanfabre on October 04, 2018, 12:39:27 AM
Hi,

 I just made it, it's now on the Ecosystem: 'SetFsmStartState'

 Bye,

 Jean
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Alatriste on November 07, 2018, 04:29:10 AM
Awesome! Thanks!
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: Alatriste on November 18, 2018, 05:31:55 AM
Quote
I just made it, it's now on the Ecosystem: 'SetFsmStartState'


Is that the name of the action? I cannot find it in the Ecosystem.
Title: Re: Restore FSM State / Save FSMs and load when loading scene
Post by: jeanfabre on November 19, 2018, 01:29:19 AM
Hi,

Right... I forgot to enable it for the ecosystem, now you can get it. Sorry about that :)

Bye,

 Jean