Machine Editor: States & Transitions

Machine Editor: States & Transitions

Machine States

Let’s dive into the Machine Editor and learn about machine states and how to create them. We will also be taking a look at parent and child machine states as well.

Transcript

Hi everyone, my name is Ren from Quicksave Interactive. We are going to be looking at the machine editor, mainly focusing on states and the hierarchy.

What are states? States are the current status or mode of your game. For example, your game may be in the paused state

or the playing state. Now the hierarchy is an extremely useful tool in managing the complex logic that can incur within your states.

Using the hierarchy, we can create events and transitions between our states as well. Let’s take a look at the machine editor to learn more about the states and hierarchy systems. Here we have the Machine Editor. I will start off by creating our first state.

In the Hierarchy panel, I will click this plus icon button. This will add our first state to our hierarchy. I am going to rename this this state root,

as it is our first state at the top of the hierarchy. I am also going to set this state as our machine’s initial state.

This will let the machine know to activate this state when the machine first runs. In addition to our root state,

let’s create a few child states as well within our root state. Let’s make sure that the root state is highlighted and active, and then let’s click the plus icon button here to create a child state which exists within the root state.

I will name this child state menu. I will also create another state within our route by selecting the route state and clicking the plus icon button again and I will call this game.

You will notice that each of the states have properties. These properties are used to define the complex logic that exists within our root state.

We can also define transitions, which allow us to create events that make it possible to move between states. As with any parent-child relationship when it comes to hierarchy systems,

it is important to remember that the child states, in this case, menu and game, will inherit the child’s the properties of the parent state, in this case,

root. This means, for example, if your root state has a button that is both active and visible, that button will also be active in the menu as well. But, because the menu and game are sibling states, if there is a button active in the menu, it will not appear in the game state.

And vice versa. In the same vein, it is also important to set an initial state for our parent state when it has children.

The machine needs to know which of its states to have active first. So, we will click on the root state and in the properties there is this initial input box.

I will set the menu as our initial state. And you can now see that both the root and the menu states are active in our hierarchy.

The machine provides us with a clear and concise way of building and managing the complexities that can exist within finite state machines. I highly encourage you to experiment with the hierarchy of states when creating your game’s flow.

In the next video, we will be discussing transitions and events, and how those are used to enter and exit states. Thank you for watching. See you again next time.

Transitions & Events

Transitions allow us to create events which can be triggered in order to switch between our various machine states.

Transcript

Hi everyone, welcome back. In this video, we will be discussing transitions and events. What are transitions? Transitions are part of your state properties.

They allow us to define events which can be triggered. Once triggered, these events allow us to move between states. Let’s take a look at the machine and how we can create transitions to move between our states. In the machine editor, we are going to be creating a transition between the menu and the game.

To do this, we will select the menu state, which you can see is our current active state. Then we are going to go to the bottom of the properties where we have the transitions section. We are going to click add item. Here we have an empty transition. For the event, I will name this “GAME”,

since it will be taking us to our game state. The target is exactly the state defined in the hierarchy, in this case, also game,

but lower case. And now, you will notice that in the events, we have this game event. This allows us to trigger the transition within the machine editor.

Let’s go ahead and trigger it. Here you can see the active state is no longer the menu state, it is now the game state.

Now let’s create a transition that allows us to move from the game state to the menu state. To do this, we will select the game state,

and in the transition section of the properties, we will add a new item. Here we will call this event “MENU”, as we will be moving to the menu.

The target will be the menu state. And now, we have this menu event in our events panel. If we click on it, our menu state is now the active state.

You will notice our events panel has updated the events to those that are available within the active state, so we can essentially move back and forth by triggering the event in the events panel.

You will also notice that the root state is always active, regardless of which child is active. This is because the root state is a parent state.

As long as any one of its children are active, the parent state will always be active. Being able to trigger events and visualize the flow of your finite state machine is one of the many reasons why the machine editor is a very powerful tool. I hope you enjoyed this tutorial and be sure to subscribe to our YouTube channel and follow our documentation website for more tutorials just like this.

Thank you and see you again next time.