Creating an FSM

Creating a Finite State Machine with GC FSM

With GC FSM, you can define multiple finite state machines in every blueprint that supports an event graph. That basically include everything: actors, components and even plain objects.

In order to create an FSM, in the blueprint editor, right-click on the background of the event graph and select “Add new FSM…” from the GC FSM category. You can immediately edit the name of the FSM.

The execution flow exiting from the start node will be a representation of the FSM. You can put almost any standard blueprint nodes in an FSM and there are two very special nodes provide by GC FSM that can only be used in an FSM, which will be described below.

You can edit the name of the FSM. The execution flow exiting from the start node represents the FSM. You can put almost any standard blueprint nodes in an FSM and there are two very special nodes provide by GC FSM that can only be used in an FSM, which will be described below.

You cannot create FSMs in graphs that are not event graphs, for example inside a function graph.

Although you can use most kind of boxes in an FSM, be careful about certain nodes that affect the execution flow, such as Sequence and ForEachLoop, since they might interact in non obvious ways with the flow of the FSM.

Add New FSM...
How to add a new FSM
The start node of an FSM. The node title is editable.

The core of the FSM: the FSM State node

A State node is the essential building block of an FSM. When the execution flow reaches a state node, the FSM is said to “enter” the state. The FSM remains in the state until a transition event is received or a timeout occurs.

In order to add a state node choose “FSM State” in the “GC FSM” category. You can immediately rename the state, for documentation purposes, if you want.

The state node is very configurable, some of the options are available in the “Details” panel, so be sure to have it visible:

  • An implementation class: this will be explained in the State Classes section;
  • Zero or more “Transition events”: each transition event has a name and is shown as an outgoing execution pin on the node. You can add, remove or reorder transition events in the “Details” panel;
  • Zero or more “Deferred events”: these are names of events that will not be handled by this state, but that we do not want to discard in order to handle them in subsequent states. You can add, remove or reorder transition events in the “Details” panel;
  • A Time Out: a time in seconds after which the state is always exited. An outgoing execution pin will be shown on the node if and only if the timeout greater than 0. The timeout can be specified on the “Details” panel or shown as a pin on the node itself. The pin is useful if you want to specify the timeout at runtime;
  • A Tick Function: this can be useful to provide recurrent processing that has to be performed while the FSM is in this state. It is provided as a convenience, since providing a Submachine class is usually a better alternative. If the Tick Function is selected in the “Details” panel, an outgoing execution pin and a DeltaTime float pin will be shown on the node.
null

While the FSM is running a State, we say that the state is “active”. Until the execution flow enters a State node and after the execution flows has exited the node, the FSM has no active state.

For each FSM, only one state can be “active” at the same time. It is an error if an execution flow enter a FSM State node while another state is active. (This situation typically never occurs, but could potentially happen if nodes like Sequence and ForEachLoop and used, which can fork the execution flow.)

How to create a new FSM State node
A pristine FSM State Node
The Details panel of an FSM State Node

Stopping an FSM

A Stop node is the second node that can be used only inside an FSM. This node is kind of boring: it has only one ingoing execution pin! If the execution flow reaches a Stop node, the FSM is stopped and its runtime resources are released.

Please ensure that all execution flows inside an FSM terminate with an FSM Stop node. Failure to do so will make the FSM enter a zombie state that is neiter stopped nor actually running. This is not a big deal, but the FSM runtime resources are not released and the FSM cannot be re-launched, if needed.

How to create an FSM Stop node
An FSM Stop node