【Unity】Starting Playmaker from scratch

STYLY users can use a visual scripting tool called Playmaker.

It is useful when creators want to make a scene that interacts and changes according to the player’s movements.

There are many articles introducing Playmaker at STYLY MAGAZINE, but I made this article for complete beginners, and to explain the basics of Playmaker. I hope you find this article helpful, and learn the concepts of Playmaker through this article.

 

Playmaker Core Concepts

Playmaker Core Concepts

 

Basic concept of Playmaker

The most important aspect of Playmaker is that it uses models called Finite State Machines (FSMs) for each game object. An FSM is used to analyze complicated movements, and you can also say that Playmaker is a tool to manage Unity using FSMs.(→Playmaker Core Concepts)。

I suppose that abstract explanation may be hard to understand, so I will try to explain using concrete examples.

What is a FSM

For example, imagine a power button of a machine. Even if a human presses the button, the answer action of the machine (whether it turns on or off) depends on the current situation.

Let’s sort this out into a graph.

 

スイッチのon/off切り替え(FSM)

Turning on/off the switch (FSM)

 

When a ‘event’ occurs as a player presses the button of a machine on an on ‘state’, the machine ‘transitions’ into an ‘off’ state. When an ‘event’ occurs on a machine on an off ‘state’, it ‘transitions’ into the on ‘state’.

Was this example easier to understand? Maybe it will be easier to understand the first FSM explanation now. FSMs are models that responds and changes according to ‘state’, ‘event’, and ‘transition’.

With this in mind, let’s look at the Playmaker Editor too.

 

unity-chanゲームオブジェクトのFSM例

FSM example of the unity-chan game object

 

This shows how unity-chan in the Walking ‘state’ ‘transitions’ into the Idle ‘state’ when the COLLISION ENTER ‘event’ occurs.

Playmaker chains multiple combinations to move game objects. In the next chapter, I will explain this in further detail.

 

3 important elements

In the last chapter, I explained about the Playmaker basic concepts, and how Playmaker uses ‘state’, ‘event’, ‘transitions’ to manage game objects. Next, I will go through the details of the 3 elements.

 

PlaymakerにおけるFSMの表示例「状態」「イベント」「遷移」

FSM examples for ‘state’ ‘event’ ‘transition’

 

State

The “Walking”, “Idle”, “Jump” are the States in the above graph. Different States do not become active simultaneously, only 1 State is active at a time.

Action is what is inside a State.

Each State has an Action, and when the State becomes active, the Action is run.

 

Actionの例:"Walking"Stateに"Animator Play"というActionを付与

Action example:Adding “Animator Play” Action to the “Walking” State

 

In the above graph, a FSM is created by Playmaker for the game object ‘unity-chan’, and an Action ‘Animator Play’ is added to the ‘Walking’ State. (Surrounded in red) When this FSM is active, ‘Walking’ becomes active with the Start Event, and ‘Animator Play’ will run.

There are many Actions in Playmaker. For example, there are actions to play an animation, move an object towards the target, create a hit box. These actions combined are used to hold States.

 

If you want to lookup Actions for certain purposes, please refer to the below article.

 

Event

The “Collision Enter” in the above graph is anEvent. An Event is a trigger for transitions.

Events such as Collision, Trigger, Mouse Input uses a value recieved from Unity, and distance checks, timeouts, game logic uses a value created by an active State action.

The former is more simple, and examples are mouse inputs, or collider hit judgments. Examples for the latter would be an event that occurs when a certain State Action records the distance to the camera, and when the distance becomes shorter than a certain amount. The following article should be a good example.

 

 

There is another type of event called Start Event. This exists from the start, and is an event that occurs when the FSM starts. The State that becomes active from the Start Event is called a Start State.

 

Start EventとStart State"Walking"

Start EventとStart State”Walking”

 

Transition

Transition is a arrow at the top of the editor. You can simply drag and drop it from the Transition Event to the next State.

There are no complicated settings needed for a Transition.

Basically, a transition starts from a certain State to another certain State, but you can create a transition without specifying a State, and make a transition that is called from a certain Event, which is called a Global Transition.

In the below example, it doesn’t matter if the current State is “Walking” or “Idle”, but when the Event “TRIGGER ENTER” is called, the State transitions to “Jump”.

 

Global Transition:"TRIGGER ENTER"というEventによって直前のStateにかかわらず"Jump"へと遷移する

Global Transition:”TRIGGER ENTER” Event makes a transition to “Jump” when called

 

Variable

There is another type of element that is important, called Variables.

Variables are something like a box with a name that you can store values inside. By using variables as an action parameter, you can create an interactive one.

Timeに"1"を入力するのではなく、"fadeInTime"という変数を設定している

Time is not set to “1”, but a variable called “fadeInTime” is used

Reference Articles

There are many Playmaker articles you can refer to in STYLY MAGAZINE.

From install to basic operations

This article explains how to install Playmaker, the basic operations, through a tutorial to create a game.

 

Example:Lamp that lights up when the player comes near

This article explains how to use Playmaker to create a VR scene easy to apply for many uses.

 

Example:Camera movement

This article explains how to implement camera movement in STYLY using Playmaker.

 

I hope this article was helpful to you, and your studies.