Saving and Restoring FSMs

Saving FSMs states

You can save the state of all FSMs of a context or state object by using the Make FSM Snapshot node. All sub-FSMs are considered, recursively. The result is an opaque FSM Snapshot object that you can later use to restore the state.

Only FSMs that are currently running are saved. FSMs that are not running will not be saved in the snapshot.

Only non-replicated FSMs can be saved. Replicated FSMs will be silently ignored and will not be saved in the snapshot.

If an FSM has no active state when making the snaphot (for example, because it is currently executing a latent function), it will not be saved in the snapshot.

The Make FSM Snapshot node can be use to create a snapshot

Restoring FSMs states

You can restore the state of the FSMs that have been saved to a snapshot object, using the Restore FSM Snapshot node. Please bear in mind:

  • If an FSM is not running when the snapshot is restored, it will be launched and the state stored in the snapshot is immediately entered (no other blocks in the FSM graph are performed)
  • If an FSM is running when the snapshot is restored, the active state is exited and then the state stored in the snapshot is entered (no other blocks in the FSM graph are performed)

In case it’s needed, you can use the Is Restoring FSM Snapshot node to check whether we are in the process of restoring a snapshot for a specific context or state object.

While restoring a snapshot, attemps to launch a new non-replicated FSM with the Launch FSM node will be silently ignored. This is made to prevent a state entry handler to launch an FSM in the wrong state, while the restoration process is going to launch it in the correct state right away.

FSMs that are not saved in the snapshot (see section above) are not affected. In particular, they won’t be stopped if they are running.

The Restore FSM Snapshot name can be used to restore a snapshot object
You can check whether we are restoring a snapshot with the Is Restoring FSM Snapshot node

Snapshot objects

Snapshots objects are opaque objects, however, in order to make it possible to serialize the state of the FSMs, convenience blocks to convert a snapshot to/from strings are provided.

Snapshot objects are specific for the context or state object that produced it. You can safely use it on objects of the same class or that you know they share the exact FSM graph. Do not use on different objects!

Snapshots objects internally store GUIDs to the graph nodes. While those GUIDs are stable between executions, modifying the blueprint graphs may potentially change those GUIDs. Please keep this in mind if you store snapshot strings persistently, since those data may become corrupted if you significantly change the blueprint graphs.

Do not try to modify the strings. Bad things will happen if a snapshot cannot be restored fully because the string has been tampered with.

You can convert a snapshot object to a string...
... and later convert the string back to a snapshot object.