State Machine

State Machine (from the theory of algorithms) is an abstract machine that has a finite set of states and transitions between them that occur in accordance with established rules.

The state machine can have different states, but only one state can be active at a time. There are some events that switch the transition of the state machine from one state to another. As a result, the state machine can perform different actions by changing its state.

The state machine is widely used in game development for creating game mechanics.

How to create a State Machine in MANU?

To create a State Machine in MANU, go to the Toolbar and click on the State Machine icon. After that, the State Machine will appear in the Scene Tree.

By default, the created state machine has the name State Machine, you can rename it using the right mouse button. Just click on the State Machine in the Scene Tree and select this option from a dropdown list. If you hit the State Machine in the Scene Tree, the new window will pop-up: State Machine Window.

How to work with the State Machine Window?

Let's look at the elements of the pop-up window. In the center, there are 2 states: State1 and Any State.

State 1 (with a blue icon) is the initial state of your State Machine by default.

Any State (with a red icon) – a special state that always exists. It is suitable for situations when it is needed to switch to a certain state, regardless of the current state of the State Machine. This is a faster way than adding an outgoing transition to each state.

Sometimes it is needed to configure transitions from all states to one. For example, when the Main Character dies, he can die being in any state. Death can occur when he is sitting or running, etc. In this case, you need to set up transitions from all states of the Main Character's state machine, which is time-consuming. For such cases, MANU provides Any State, using which you need to configure only one transition.

Note: Any State cannot be the final point of the transition, i.e. the transition to “any state” cannot be used to select a random state.

The Minimize/Maximize and Close buttons are located at the right end of the title bar.

Toolbar

The toolbar is located in the upper left corner:

SELECT — using this tool, you can select state objects and move them;

STATE — you can use it to add a new state;

CONNECTOR – you can use it to create connections between states;

PAN — allows the user to quickly switch to panning the canvas. .

Furthermore, it is also possible to add a new state using the right mouse button if you first click on SELECT. You can also create a state by double-clicking on the canvas.

By right-clicking on the State, you can open the context menu with a set of actions which you can apply to the State. Using this menu, you can rename, duplicate, cut, copy, delete the state, as well as add color labels. Most of the commands are accessible via hotkeys. Furthermore, it is possible to rename the State by double-clicking on its name.

Color labels

Color labels are used to visually design transitions from one state to another, which is very convenient when a state machine has many states and connections between them. To add labels, just right-click on the State and choose the color you want to mark it with.

Creating Transitions between states

To set the connection between states, you first need to select Connector on the Toolbar. Then click on the State, from which you need to make a transition, and drag the line to another State holding down the left mouse button. For example, drag the line from State 1 to State 2.

A dotted line with an arrowhead will appear between these states. The dotted line means that the link between State 1 and State 2 has been created, but it is not configured, i.e. the rule has not been created yet. It is not described how the transition from one state to another will take place. This dotted line can be moved, its shape can be changed. All this can be done by clicking on and dragging the left mouse button. The shape of the line does not affect the transition between states. Therefore, it can be drawn in any shape.

Configuring a Transition rule

When you click on the dotted line, a Trigger Panel will appear. Using this panel, you can create a rule for the transition from one state to another. Just choose a trigger you need.

The Trigger Panel closes when you click on any area of the State Machine Window. After creating a rule, the dotted line will turn to a solid, continuous line. It means that the connection between states has been configured; and the transition rule from one state to another is established. In addition, when you hover over the line, the transition rule will be shown in the tooltip (for example, Key Down: 0).

One state can have several connection lines with other states. Multiple transitions can be made from one state, as well as into it.

Last updated