API

The Behavior Tree component is the main interface between Behavior Designer and the behavior tree data. It is also responsible for baking if the component is placed within an Entity subscene. The Behavior Tree component has the following API:

/// <summary>
/// Starts the behavior tree.
/// </summary>
/// <returns>True if the behavior tree was started.</returns>
bool StartBehavior()

 /// <summary>
/// Stars the branch with the specified event task type.
/// </summary>
/// <param name="eventTaskType">The branch that should be started.</param>
/// <returns>True if the branch was started.</returns>
bool StartBranch(Type eventTaskType)

 /// <summary>
/// Starts the branch with the specified event task.
/// </summary>
/// <param name="eventTask">The branch that should be started.</param>
/// <returns>True if the branch was started.</returns>
bool StartBranch(IEventNode eventTask)

 /// <summary>
/// Returns the task at the specified index.
/// </summary>
/// <param name="index">The index of the task.</param>
/// <returns>The task at the specified index.</returns>
ILogicNode GetTask(int index)

 /// <summary>
/// Ticks the behavior tree. The UpdateMode must be set to Manual.
/// </summary>
void Tick()

 /// <summary>
/// Reevaluates the SubtreeReferences by calling the EvaluateSubtrees method.
/// </summary>
void ReevaluateSubtreeReferences()

 /// <summary>
/// Stops or pauses the behavior tree.
/// </summary>
/// <param name="pause">Should the behavior tree be paused?</param>
/// <returns>True if the behavior tree was stopped or paused.</returns>
bool StopBehavior(bool pause = false)

 /// <summary>
/// Restarts the behavior tree.
/// </summary>
/// <returns>True if the behavior tree was restarted.</returns>
bool RestartBehavior()

 /// <summary>
/// Returns the SharedVariable with the specified name and scope.
/// </summary>
/// <param name="name">The name of the SharedVariable that should be retrieved.</param>
/// <param name="scope">The scope of the SharedVariable that should be retrieved.</param>
/// <returns>The SharedVariable with the specified name (can be null).</returns>
SharedVariable GetVariable(string name, SharedVariable.SharingScope scope)

 /// <summary>
/// Saves the behavior tree at the specified file path.
/// </summary>
/// <param name="filePath">The file path to save the behavior tree at. The file will be replaced if it already exists.</param>
/// <param name="variableSaveScope">Specifies which variables should be saved. Graph variables will automatically be saved.</param>
/// <returns>True if the behavior tree was successfully saved.</returns>
bool Save(string filePath, SaveManager.VariableSaveScope variableSaveScope)

 /// <summary>
/// Loads the behavior tree from the specified file path.
/// </summary>
/// <param name="filePath">The file path to load the behavior tree at.</param>
/// <returns>True if the behavior tree was successfully loaded.</returns>
bool Load(string filePath)

If your behavior tree is set to a Manual Update Mode then you will need to tick the tree by calling BehaviorTree.Tick. This is useful for turn-based games.

Events

The following events are exposed:

OnBehaviorTreeEnabled
OnBehaviorTreeDisabled
OnBehaviorTreeDestroyed

OnWillSave
OnDidSave
OnWillLoad
OnDidLoad

It can also be useful to check the execution status of the tree and you can do that with the BehaviorTree.Status property.