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.
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.
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.