I know that it’s possible to serialize blackboard and graph at runtime, but is it possible to serialize current execution state?
I really want to have fsm/tree and flow canvases to be saved at position where they were at the time of save 🙂
If someone is looking for solution for a similar question
FSMOwner rather easy to serialize – just serialize index of currentState and on load apply it through EnterState
Behaviour Tree – we don’t need it
FlowGraph – for now I have no solution how to serialize current execution state of it, would be happy to be pointed into a right direction
There is no way to save the exact point and state of execution at any given time in either of the systems, but you can of course save the blackboard variables that they use.
For FSM, like you said, you can also save the currentState.
Behaviour Trees, should be designed in a way to be able to recreate the execution state based on the conditions and variables the tree is using.
Flowscripts on the other hand, since they are event-based, their execution state is mostly temporary and lasts for as long as the event flow signal lasts. In other words, flowscripts don’t practically have any execution state which we can store since all non temporary data are stored in the variables that it is using instead (which we can serialize independently).
But, when it goes to flowcanvas, it should be possible to save current execution stack along side with blackboard
Currently I’m saving all blackboards and FSM’s (tree’s, as you said, don’t need to be serialized – they reconstruct their behavior right after load), but having ability to save flowcanvas is critical for me
Is there a point where I can start my investigation/hack to add flow canvas stack serialization?
The problem as I stated before, is that an FC flowscript -as a system-, does not really has any notion of a “state”.
More or less execution of a flow is instant (1 frame), where the only case where it is not, is in the case of some latent node usage like Wait, Coroutine or Tween, where depending on the graph design, more than one can be active and still be totally irrelevant to each other.
I honestly can’t see how saving a flowscript ‘snapshot’ can be achieved if at all, but probably the things to look out for, would be re-starting the nodes that are not instant (wait, courtine etc), along with loading it’s internal private and temporary variables that are used for them (like time remaining etc).
I would really instead just avoid allowing the player to save the game right in the middle of an execution process though and like most games do, allow saving only at certain “checkpoints” 🙂
Currently I’ve decided to skip flowcanvas serialization, I’ll save blackboard and current variables from flowcanvas and right after game is loaded I’ll send an event to notify that flowcanvas was loaded, script writer must support serialization of his flowcanvas on his own (if he really needs to)