Unity Behavior Tree Plugin BehaviorDesigner

Hits: 0

BehaviorDesigner – [behavior tree] for controlling and implementing AI logic

A Behavior: the settings of this behavior tree

Two Tasks: all node Tasks of the behavior tree

In the Behavior Designer plug-in, there are four main concept nodes, which are called Task. include:

(1) Composites combination node

Includes classics: Sequence, Selector, Parallel

Abort Type Abort Type

The priority and interruption of the composite class Task:

This is very important and is the only special attribute of the composite class Task: it is divided into four types – not interrupted, can interrupt itself, can interrupt other tasks lower than the task priority, can interrupt itself or interrupt interrupt lower than its priority.
It should be noted that the interrupt condition of the compound node is that its sub-nodes must have conditional nodes. At this time, the judgment of the conditional node is always in the running state. Once the conditional node changes at a certain moment, the behavior tree will jump again. Go to the compound node location to continue running, interrupting other running low priority nodes.

(2) Decorator decoration node

, as the name suggests, is to add some additional functions to the only child node,
such as letting the child task run until it returns a certain running status value, or inverting the return value of the task, etc.

(3) Actions behavior node

, the behavior node is the node that actually does things, which is a leaf node. The Behavior Designer plug-in comes with a lot of Action nodes. If it is not enough, you can also write your own Action. Generally speaking, you have to write your own Action,
unless the user is an artist or planner who does not understand scripting, and just wants to simply control the properties of some objects.

(4) Conditinals condition node

, which is used to determine whether a condition holds. At present, it seems that in order to implement the principle of single responsibility, Behavior Designer
treats the judgment as a node independently, such as judging whether a certain target is in the field of view, in fact, it can also be written in the attacking Action, but this way
the Action is not single, It is not conducive to the reuse of visual field judgment processing. The general condition node appears in the [Sequence] control node, followed by the Action node after the condition is established.

Custom Task task:

Tasks of general composite classes and decorative classes are sufficient, and some are not even used at all, while specific behavioral tasks and conditional tasks have never been able to meet our needs, and writing such tasks by yourself can greatly simplify The entire behavior tree structure.

The steps to write your own Task are as follows:

1. Introduce the namespace:

1  using BehaviorDesigner.Runtime;
    2  using BehaviorDesigner.Runtime.Tasks;

2. Explicitly inherited Task type:

1   public class MyInputMove : Action
    2   public class MyIsInput : Conditional

Observing the above figure, you will find that it is similar to writing scripts in Unity. The difference is that the Update here has a return value. To return the execution status of the task, it is only called every frame when it is in the Running state.

using UnityEngine;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;

public class MyInputMove : Action
{
    public SharedFloat speed = 5f;
    public override TaskStatus OnUpdate()
    {
        float inputX = Input.GetAxis("Horizontal");
        float inputZ = Input.GetAxis("Vertical");
        if (inputX != 0 || inputZ != 0)
        {
            Vector3 movement = new Vector3(inputX, 0, inputZ);
            transform.Translate(movement*Time.deltaTime*speed.Value);
            return TaskStatus.Running;
        }
        return TaskStatus.Success;
    }
}

Another difference is that Task encapsulates a layer of Share type attributes. What is the difference between it and non-Share type?
Here’s a comparison:

using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;

public class MyLog : Action
{
    public string staticLog;
    public SharedString shareLog;

    public override TaskStatus OnUpdate()
    {
        Debug.Log(staticLog + shareLog.Value);
        return TaskStatus.Success;
    }
}

Another difference is that Task encapsulates a layer of Share type attributes. What is the difference between it and non-Share type?
Here’s a comparison:

using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;

public class MyLog : Action
{
    public string staticLog;
    public SharedString shareLog;

    public override TaskStatus OnUpdate()
    {
        Debug.Log(staticLog + shareLog.Value);
        return TaskStatus.Success;
    }
}

It can be seen that the type of Share here is a variable that is convenient to pass and modify in the behavior tree, because it is inconvenient to directly modify other Task variables between tasks, so what should we do, so we add a type of Share variable Communicate between the various tasks of the behavior tree.

For example, here, the nearest enemy found is different each time, according to the value returned by the previous task to execute the attack of the next task or print the result, then the fixed attributes cannot meet the requirements, but directly call other tasks It also increases the coupling, so the Share variable is used alone to pass the value. This also facilitates unified viewing and management in the panel.

In addition, Share variables can also add custom types. The difference between global and local variables is that one exists in all behavior trees, and the other exists only in this tree.

.Value is required when taking the value of the Share variable.

Three Variables: Generic Variables for Behavior Trees

It is used for the communication of variables between all nodes of this behavior tree (for example, the A node is the task of finding the enemy, after finding the target of the enemy, put this
    Each target is set to the general variable, and the task of node B gets the target from this general variable to execute the attack task

Four Inspectors:

After clicking on a node, the detailed information of the node is displayed, and public variables can be set

You may also like...

Leave a Reply

Your email address will not be published.