BehaviorTree
Inherits:
Contains Behavior Tree data.
Description
Behavior Trees are hierarchical structures used to model and control the behavior of agents in a game (e.g., characters, enemies, entities). They are designed to make it easier to create complex and highly modular behaviors for your games.
Behavior Trees are composed of tasks that represent specific actions or decision-making rules. Tasks can be broadly categorized into two main types: control tasks and leaf tasks. Control tasks determine the execution flow within the tree. They include BTSequence, BTSelector, and BTInvert. Leaf tasks represent specific actions to perform, like moving or attacking, or conditions that need to be checked. The BTTask class provides the foundation for various building blocks of the Behavior Trees. BT tasks can share data with the help of Blackboard. See BTTask.blackboard and Blackboard.
Note: To create your own actions, extend the BTAction class.
The BehaviorTree is executed from the root task and follows the rules specified by the control tasks, all the way down to the leaf tasks, which represent the actual actions that the agent should perform or conditions that should be checked. Each task returns a status when it is executed. It can be SUCCESS, RUNNING, or FAILURE. These statuses determine how the tree progresses. They are defined in Status.
Behavior Trees handle conditional logic using condition tasks. These tasks check for specific conditions and return either SUCCESS or FAILURE based on the state of the agent or its environment (e.g., “IsLowOnHealth”, “IsTargetInSight”). Conditions can be used together with BTSequence and BTSelector to craft your decision-making logic.
Note: To create your own conditions, extend the BTCondition class.
Check out the BTTask class, which provides the foundation for various building blocks of Behavior Trees.
Properties
|
|
Methods
clone() const |
|
void |
copy_other(other: BehaviorTree) |
get_root_task() const |
|
instantiate(agent: |
|
void |
set_root_task(task: BTTask) |
Signals
plan_changed() 🔗
Emitted when the BlackboardPlan changes.
Property Descriptions
BlackboardPlan blackboard_plan 🔗
void set_blackboard_plan(value: BlackboardPlan)
BlackboardPlan get_blackboard_plan()
Stores and manages variables that will be used in constructing new Blackboard instances.
String description = "" 🔗
void set_description(value:
String)Stringget_description()
User-provided description of the BehaviorTree.
Method Descriptions
BehaviorTree clone() const 🔗
Makes a copy of the BehaviorTree resource.
void copy_other(other: BehaviorTree) 🔗
Become a copy of another behavior tree.
BTTask get_root_task() const 🔗
Returns the root task of the BehaviorTree resource.
BTInstance instantiate(agent: Node, blackboard: Blackboard, instance_owner: Node, custom_scene_root: Node = null) const 🔗
Instantiates the behavior tree and returns BTInstance. instance_owner should be the scene node that will own the behavior tree instance. This is typically a BTPlayer, BTState, or a custom player node that controls the behavior tree execution. Make sure to pass a Blackboard with values populated from blackboard_plan. See also BlackboardPlan.populate_blackboard & BlackboardPlan.create_blackboard.
If custom_scene_root is not null, it will be used as the scene root for the newly instantiated behavior tree; otherwise, the scene root will be set to instance_owner.owner. Scene root is essential for BBNode instances to work properly.
void set_root_task(task: BTTask) 🔗
Assigns a new root task to the BehaviorTree resource.