Reply To: Save state and the current active node in State Machine

NodeCanvas Forums Support Save state and the current active node in State Machine Reply To: Save state and the current active node in State Machine

#11746
zsoik
Participant

We required the same (saving execution state of FSMs) and there isn’t official support for doing that (correct me if I’m wrong). We settled with the following, although it restricts the usage of FSMs a bit:

– Implement a new custom FSM node called “Checkpoint”, which has a GUID assigned to uniquely identify it (node identities themselves could change when the FSM is edited which is often the case during development, so we need to rely on a more robust way of identifying the same checkpoint across different FSM versions)
– Checkpoint will store its GUID and the serialized blackboard content into two blackboard variables, like “__checkpoint_id” and “__checkpoint_blackboard”. This essentially gives us a execution state snapshot when the checkpoint state is crossed
– To store FSM state, we write the two checkpoint variables of the blackboard into the savegame
– To restore the FSM state, we load the checkpoint id and blackboard data from the savegame, de-serialize the blackboard contents and set the recovery checkpoint node to the start node of the fsm. This will restart the FSM at the checkpoint it was stored at with the same blackboard contents

Some more magic may be required to make this fully work, though, like using proxy objects in the blackboard that can be serialized to recover game object references upon restoration, as the blackboard won’t reliably store UnityEngine.Object references when serializing a blackboard at runtime.