Behavior Tree Component

The behavior tree component stores your behavior tree and acts as the interface between Behavior Designer and the tasks. The following API is exposed for starting and stopping your behavior tree:

public void EnableBehavior();
// pause:  temporarily stop the behavior tree at its current execution point. It can be resumed with EnableBehavior.
public void DisableBehavior(bool pause = false);

You can find tasks using one of the following methods:

TaskType FindTask<TaskType>();
List<TaskType> FindTasks<TaskType>();
Task FindTaskWithName(string taskName);
List<Task> FindTasksWithName(string taskName);

The current execution status of the tree can be obtained by calling:

behaviorTree.ExecutionStatus

A status of Running will be returned when the tree is running. When the tree finishes the execution status will be Success or Failure depending on the task results.

The following events can also be subscribed to:

OnBehaviorStart
OnBehaviorRestart
OnBehaviorEnd

The behavior tree component has the following properties:

Behavior Name

The name of the behavior tree.

Behavior Description

Describes what the behavior tree does.

External Behavior

A field to specify the external behavior tree that should be run when this behavior tree starts.

Group

A numerical grouping of behavior trees. Can be used to easily find behavior trees. The CTF sample project shows an example of this.

Start When Enabled

If true, the behavior tree will start running when the component is enabled.

Asynchronous Load

Specifies if the behavior tree should load in a separate thread. Because Unity does not allow for API calls to be made on worker threads this option should be disabled if you are using property mappings for the shared variables.

Pause When Disabled

If true, the behavior tree will pause when the component is disabled. If false, the behavior tree will end.

Restart When Complete

If true, the behavior tree will restart from the beginning when it has completed execution. If false, the behavior tree will end.

Reset Values On Restart

If true, the variables and task public variables will be reset to their original values when the tree restarts.

Log Task Changes

Used for debugging. If enabled, the behavior tree will output any time a task status changes, such as it starting or stopping.