Getting Started


Information “Arbor: State Diagram Editor”

  • I want to make games using the finite state machine in Unity!
  • However, behavior that depends on the game logic want to coding on your own!
  • And the edit window of likely finite state machine used at such time,
    It is a simple state machine asset to write the state of the script to match the behavior you want to create.

What is finite state machine (FSM)?

  • The finite state machine, and behavior in a certain state, it is a mechanism for transition from the state to another.
  • For example, switches and lights.
  • The switch and the lamp there is a state of ON and OFF, will also be ON lamp if the ON switch.
  • Switch is switched to ON If you press, is the behavior to switch to OFF and press again.
  • Electric light will be the behavior to put the lights if ON.

Use far from in the game

Many of the game, I think I would be represented in the transition of state and behavior.
For example, the enemy of the movement might be as follows.

  • “Awake state”.
    Enemy it takes a generation motion Once generated.
    After the motion ends, the transition to “patrol state”.
  • “Patrol state”.
    Consider How trying it while appropriately patrol.
    When are near the player, the transition if the HP high of enemy itself to the “tracking state”.
    The transition if HP low to “escape state”.
  • “Tracking state”.
    To move to a position where you can attack the player.
    After arriving in the attack can be located, a transition is made to “attack the state.”
  • “Attacking state”.
    Attack!
    After the end of the attack motion, it returns to the “patrol state”.
  • “Escape state”.
    I run away from the found player.
    With confidence when away far to return to the “patrol state”.

In this example, we have branch whether to flee or to track in their own HP.
Although it is a branch of in just one place, I do not know immediately that you are where How about led When I was in the sentence.
If you are a complex movement, such as the final boss is also complicated and also behavior state is impossible also possible that further work is more of a state machine.
Patrol time there, some time fled, behavior in the finely script called,
After that better to the shape you want to edit the relationship between the transition in the editor will think whether to also improve well become the development efficiency is visual.

You can use the Arbor, you can partnering in this way the transition of visual state.

Get the Arbor

Preparation for using Arbor

Project creation

If you do not have a project that uses Arbor, you need to create a new project.

For details on how to create a project, see Getting started in the Unity Manual.

By choosing Arbor 2 from the “Asset packages” button, you can skip importing work later.

If you can not find the Arbor 2 package in the list, see “Importing Arbor” below.

Finally, press the “Create Project” button to create the project.

Arbor import

This task is necessary if you did not import the Arbor 2 package in “Create Project” or if you want to import Arbor into an already existing project.

To import Arbor, first display the AssetStore window.

From the menu, select “Window > Asset Store” or press Ctrl + 9 on the shortcut.

When the AssetStore window is displayed, click the Toggle Download Manager icon on the toolbar to switch to Download Manager.

If you see a lot of assets displayed and Arbor 2 package can not be found immediately, please use the filter.

Set Group by to “Title”, Filter to “Arbor 2”, and press the Filter button to narrow down.

Click the Import button on Arbor 2 to display the Import Unity Package window.

If there is no Import button and it is a Download button, you can not download yet, please click the Download button first.

Import is completed by clicking the Import button at the lower right of the window.

How to use

About ArborFSM

ArborFSM is the main component of Arbor.

You can combine in-game logic by adding ArborFSM to GameObject and setting nodes such as State in the ArborEditor window.

Additional ArborFSM

  • Choose you want to apply GameObject
    Select “menu> Component> Arbor> ArborFSM”.
  • Alternatively, select the “Add Component button> Arbor> ArborFSM” of Inspector.
    GIF
  • In addition, GameObject from the Hierarchy of the Create button “Arbor> ArborFSM” state ArborFSM is attached can create.
    GIF

Open the Arbor Editor

  • Click on the ArborFSM Open Editor button that you want to edit.
    Arbor Editorを開く(Open Editorボタンから)
    Alternatively, select the “Menu> Window> Arbor Editor”

Selection of ArborFSM

  • Arbor Editor and drag-and-drop to the top of the selection box.
    Or selected from the list by clicking on the selection box.
    Select ArborFSM
  • Automatically become selected state when you press the Open Editor button in the Inspector of ArborFSM.

Creating States

  • Right-click the appropriate position of Arbor Editor.
    Click on the “Create State”.
    GIF

The name change of node

  • Double click on the header part at the top of the inside of the node frame, select “Rename” from right click or setting icon.
    Enter in the displayed text box.
    GIF

Specifying the starting state

The starting state, when an object is activated, it is the state that is executed at the beginning most.
(It will automatically start state when you create a state in the absence of starting state.)

  • Click on the state name next to the setting icon.
    Select “Set Start State.”
    GIF

Delete Node

  • Click to select nodes.
  • Right-click on an empty area and select “Delete”, or press the Delete key.
    GIF

Add the behavior in the state

  • Click on the state name next to the setting icon.
  • Select “Add Behaviour”.
  • Select the behavior you want to add from the behavior list.
    GIF
  • It may assert a direct drag-and-drop script file you want to add behavior.

Delete of behavior

  • Click the behavior name next to the setting icon.
  • Click the “Delete”.
    GIF

The behavior on transition

Behavior on the transition is built some from the beginning.

  • Select “Add Behaviour” from the settings icon next to the state name.
    Behavior of the transition system is contained within the Transition.
    GIF
  • There is such TimeTransition to transition in time.

Open the Behaviour manual

For the built-in behavior, open the manual page in the browser by clicking on the help icon.

  • Click the help icon next to the title bar of various behaviors

Connection from the behavior to the state

  • It advance is adding the behavior of the transition system such as TimeTransition.
  • The drag-and-drop from the state connection area to another State.
  • Canceled if tied at nothing
    GIF

Transition line right click menu

Right click on the transition line to display the menu to move to the transition source and transition destination.

GIF

About TransitionTiming

Transition timing is not always instantaneous but it depends on TransitionTiming specification.

TransitionTiming can be done by opening the setting window of the transition slot by clicking the setting icon.

GIF

The behavior of TransitionTiming is as follows.

Late Update Overwrite Reserve to transition when LateUpdate.
If the transition is already reserved in the same frame, overwrite it.
Immediate Transit immediately upon transition call.
If the transition is looping, there is a possibility of infinite looping, so use with caution.
Late Update Dont Overwrite Reserve to transition when LateUpdate.
If the transition is already reserved within the same frame, do not overwrite it.
(Arbor 2.2.0 or later default)

About Resident State

Resident state constantly movement state, and then use when you want to forcibly interrupted pending (such as collisions).
Please be careful to point instead to continue the movement does not accept a transition from other states.

  • Right-click the appropriate position of Arbor Editor.
    Click the “Create Resident State”.
    GIF

Choose how to specify the value

  • If there is a field next to  mark of each property, you can choose how to specify the value by clicking.
    GIF
  • Unlike the choice depending on the type of value, it is as follows for the Lord.
    • Constant
      Specify a fixed value
    • Parameter
      Refer to the parameter.
      For details on parameters, see “About ParameterContainer” below.
    • Random
      Get at random from within the specified range.
    • Calculator
      It accepts the input from the operation node.
      For details about computation nodes, see “About calculator node” below.

About calculator node

By the calculator node, input and output and operation of the variable you will be able to on the Arbor Editor.

Creating a calculator node

  • Right-click the appropriate position of Arbor Editor.
  • Click on the “Create Calculator”.
  • Select the calculator node you want to create from the list.
    GIF

Connection of the calculator slot

  • Drag and drop the input or output slot to connect.
    Release when there is nothing during drag & drop from the input slot and release.
    GIF

State List

  • Open and close by clicking on the “State List” in the toolbar.
  • A list of state is displayed on the left side is selected by clicking the state.
    GIF
  • From the search bar, search by name (some matches), Search by type of behavior (match-all) is possible.
    GIF

About Parameter container

ParameterContainer is a component used when sharing data between ArborFSM and others.

Add ParameterContainer to GameObject and set various types of parameters.

Addition of ParameterContainer

  • Choose you want to apply GameObject
    Select “menu> Component> Arbor> ParameterContainer”.
  • Alternatively, select the “Add Component button> Arbor> ParameterContainer” of Inspector.
    GIF
  • Also, you can create a GameObject with ParameterContainer attached from Hierarchy’s Create button “Arbor> ParameterContainer”.
    GIF

Additional parameters

  • Click on the bottom right of the + button in the “Parameters”.
    Select the type you want to add.
    GIF

Edit parameters

  • Name, select a value editing.
    GIF

Delete parameters

  • Select the parameter and click the – button.
    GIF

About GlobalParameterContainer

GlobalParameterContainer is a component to use when there are parameters that you want to keep even if you change the scene.

Addition of GlobalParameterContainer

  • Choose you want to apply GameObject
    Select “menu> Component> Arbor> GlobalParameterContainer”.
  • Alternatively, select the “Add Component button> Arbor> GlobalParameterContainer” of Inspector.
    GIF
  • Also, you can create a GameObject with GlobalParameterContainer attached from Hierarchy’s Create button “Arbor> GlobalParameterContainer”.
    GIF

Setting GlobalParameterContainer

  • ParameterContainer with parameters to be shared between scenes is created in advance and Prefabized.
  • Select GameObject to which GlobalParameterContainer is added.
    Specify Prefab of ParameterContainer created in Prefab of Inspector.
    GIF

Coding

You can prepare the behavior and the processing of your own to create a script of C#, JavaScript,Boo.

Creating a script file

  • Right-click on the location you want to create from the Project window.
  • From the right-click menu, and select your favorite language from the “Create> Arbor > State Behaviour”.
    スクリプトファイルの作成
  • Determined to enter the file name

State Connection

  • Declare StateLink wearing a public or SerializeField attribute to the script that you have created.
    The declaration automatically become editable Arbor Editor if.

    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour {
    	public StateLink nextState;
    	// Approximately
    }
    

  • It is referred to as the Transition in the transition you want to timing.
    Transition( nextState );
    

Input from the calculator node

  • Declare and InputSlotInt and InputSlotFloat wearing a public or SerializeField attribute to create scripts.
    (For InputSlot<T> generic class can not be serialized on the Unity of the specification, please use the class was always inherited)
    Automatically become editable Arbor Editor if the declaration.

    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public InputSlotInt slotInt;
    	// Approximately
    }
    

  • To get the value is to use the GetValue method.
    int data = 0;
    slotInt.GetValue(ref data);
    if (data == 10)
    {
    	Debug.Log("Test");
    }
    

Input from the calculator node(Flexible)

  • Declare and FlexibleInt and FlexibleFloat wearing a public or SerializeField attribute to create scripts.
    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public FlexibleInt flexible;
    	// Approximately
    }
    


    If you select Calculucator in ArborEditor window accepts an input from the computing node.

  • To get the value is to use the value property.
    if (flexible.value == 10)
    {
    	Debug.Log("Test");
    }
    

Output to the calculator node

  • Declare and OutputSlotInt and OutputSlotFloat wearing a public or SerializeField attribute to create scripts.
    (For OutputSlot<T> generic class is not serialized on the Unity of the specification, please use the class was always inherited)
    Automatically become editable Arbor Editor if the declaration.

    using UnityEngine;
    using Arbor;
    
    public class TestBehaviour : StateBehaviour
    {
    	public OutputSlotInt slotInt;
    	// Approximately
    }
    

  • To set the value to use the SetValue method.
    slotInt.SetValue(10);
    

Editor extension

  • Such as available inspector extension and PropertyDrawer is I can also be used to StateBehaviour in Unity

Important point

  • For enabled of MonoBehaviour are used internally already for execution control, please use the behaviourEnabled to be a substitute.

To the next step