Referencing Tasks
A custom task can reference another task in the same tree when it genuinely
needs that task instance. Prefer variables for ordinary data
flow so tasks remain loosely coupled.
Declare a task reference
Expose the exact task type or an array of that type:
using BehaviorDesigner.Runtime.Tasks;
using UnityEngine;
public class ReadSensorThreshold : Action
{
public DistanceSensor ReferencedTask;
public override void OnAwake()
{
Debug.Log(ReferencedTask.Threshold);
}
}
public class DistanceSensor : Conditional
{
public float Threshold;
}
After Unity compiles, select ReadSensorThreshold, use the select control beside
Referenced Task, and then choose the matching task in the graph. The identify
control highlights the linked task; the clear control removes the reference.
For multiple references, declare public DistanceSensor[] ReferencedTasks; and
assign each element through the same link mode.
Keep paired links synchronized
Add [LinkedTask] to a task field when assigning one side should also maintain
the reciprocal task link. This is useful for paired coordination tasks, but it
does not replace a shared variable for values.
Troubleshooting
- A task cannot be selected: the graph task must be assignable to the exact
declared field type. - The reference becomes null after restructuring: relink the field after
replacing or deleting the original task. - A reusable external tree has an unexpected dependency: pass data through a
variable instead; direct task references intentionally bind to one tree
structure.