Home

Awesome

OpenBehaviourTree

OpenBehaviourTree is an open source tool to design and monitor behaviour trees visually in Unity.

OpenBehaviourTree

Features

Installation

Tested on Windows 10 using Unity 2021.2.11f1

Getting Started

Creating a new tree

OpenBehaviourTree works as a custom editor. To create a behaviour tree right-click in a given folder in your Project view, and choose Create --> BehaviourTree. Most behaviour trees will also need a blackboard (Create --> BehaviourTreeBlackboard). Double-clicking on the newly created BehaviourTree will then open an editor window with a single Root node. This is the base of your tree.

Navigation

To move around the tree left-click and drag the mouse. Zoom is controlled with the mouse wheel, and nodes can be moved by left-clicking and dragging them.

Adding nodes

On the right-hand side is the Details panel. Clicking on the Blackboard tab will allow you to add a given blackboard. Here you can also add blackboard keys that can be used in the behaviour tree.

To begin adding nodes left-click the bottom connection point of the Root node. This will begin to draw a connection from the node to your cursor. Left-clicking anywhere on the grid will then give a series of options for creating a node. Right-clicking while drawing a connection cancels the connection. When left-clicking on a given node, its details are shown in the Details panel when looking at the Selected tab, along with any properties that can be modified by the user. Decorators can be added to a node by right-clicking on the nodes.

Creating custom Actions

Action nodes can be created from anything that derives from BehaviourTreeTask. A new action class just needs to implement two things:

GetInt(string keyName)
GetBool(string keyName)
GetFloat(string keyName)
GetGameObject(string keyName)
GetString(string keyName)
GetVector3(string keyName)
GetVector2(string keyName)

SetInt(string keyName, int val)
SetBool(string keyName, bool val)
SetFloat(string keyName, float val)
SetGameObject(string keyName, GameObject val)
SetString(string keyName, string val)
SetVector3(string keyName, Vector3 val)
SetVector2(string keyName, Vector2 val)

So, for example, an action that added force to the GameObject can be written like this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleTask : Behaviour.BehaviourTreeTask
{
    Rigidbody rb;
    
    public override void Setup(MonoBehaviour monoBehaviour){
        rb = monoBehaviour.GetComponent<Rigidbody>();        
    }
    
    public override IEnumerator ExecuteTask(System.Action<Behaviour.NodeState> currentState){
    
        // Put the node in the Running state
        currentState(Behaviour.NodeState.Running);
        
        // Get values from the blackboard
        Vector3 force = blackboard.GetVector3("currentForce");
        float timeDelay = blackboard.GetFloat("timeDelay");
        
        // Carry out the task
        rb.AddForce(force);
        yield return new WaitForSeconds(timeDelay);
        
        // Put the node in the Succeeded state
        currentState(Behaviour.NodeState.Succeeded);
    }
}

Attaching a behaviour tree to a GameObject

Core Node Types

OpenBehaviourTree

Nodes that can be added to core node types

Running Tests

TODO

Further Info