Referencing Tasks

When writing a new task, in some cases it is necessary to access another task within that task. For example, TaskA may want to get the value of TaskB.SomeFloat. To accomplish this, TaskB needs to be referenced from TaskA. In this example TaskA looks like:

using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;

public class TaskA : Action
{
   public TaskB referencedTask;

   public void OnAwake()
   {
      Debug.Log(referencedTask.SomeFloat);
   }
}

TaskB then looks like:

using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;

public class TaskB : Action
{
   public float SomeFloat;
}

Add both of these tasks to your behavior tree within Behavior Tree and select TaskA.

Click the select button. You’ll enter a link mode where you can select other tasks within the behavior tree. After you select Task B you’ll see that Task B is linked as a referenced task:

That is it. Now when you run the behavior tree TaskA will be able to output the value of TaskB’s SomeFloat value. You can clear the reference by clicking on the “x” to the right of the referenced task name. If you click on the “i” then the linked task will highlight in orange:

Tasks can also be referenced using an array:

public class TaskA : Action
{
   public TaskB[] referencedTasks;
}