BTPlayer

Inherits:

Player of BehaviorTree resources.

Description

BTPlayer node is used to instantiate and play BehaviorTree resources at runtime. During initialization, the behavior tree instance is given references to the agent, the blackboard, and the current scene root. The agent can be specified by the agent_node property (defaults to the BTPlayer’s parent node).

For an introduction to behavior trees, see BehaviorTree.

Properties

bool

active

true

NodePath

agent_node

NodePath("..")

BehaviorTree

behavior_tree

Blackboard

blackboard

BlackboardPlan

blackboard_plan

bool

monitor_performance

false

UpdateMode

update_mode

1

Methods

BTInstance

get_bt_instance()

void

restart()

void

set_bt_instance(bt_instance: BTInstance)

void

set_scene_root_hint(scene_root: Node)

void

update(delta: float)


Signals

behavior_tree_finished(status: int) 🔗

Deprecated: Use updated signal instead.

Emitted when the behavior tree has finished executing and returned SUCCESS or FAILURE.

Argument status holds the status returned by the behavior tree. See Status.


updated(status: int) 🔗

Emitted when BTPlayer has finished the behavior tree update.

Argument status holds the status returned by the behavior tree. See Status.


Enumerations

enum UpdateMode: 🔗

UpdateMode IDLE = 0

Execute behavior tree during the idle process.

UpdateMode PHYSICS = 1

Execute behavior tree during the physics process.

UpdateMode MANUAL = 2

Behavior tree is executed manually by calling update.


Property Descriptions

bool active = true 🔗

  • void set_active(value: bool)

  • bool get_active()

If true, the behavior tree will be executed during update.


NodePath agent_node = NodePath("..") 🔗

  • void set_agent_node(value: NodePath)

  • NodePath get_agent_node()

Path to the node that will be used as the agent. Setting it after instantiation will have no effect.


BehaviorTree behavior_tree 🔗

BehaviorTree resource to instantiate and execute at runtime.


Blackboard blackboard 🔗

Holds data shared by the behavior tree tasks. See Blackboard.


BlackboardPlan blackboard_plan 🔗

Stores and manages variables that will be used in constructing new Blackboard instances.


bool monitor_performance = false 🔗

  • void set_monitor_performance(value: bool)

  • bool get_monitor_performance()

If true, adds a performance monitor to “Debugger->Monitors” for each instance of this BTPlayer node.


UpdateMode update_mode = 1 🔗

Determines when the behavior tree is executed. See UpdateMode.


Method Descriptions

BTInstance get_bt_instance() 🔗

Returns the behavior tree instance.


void restart() 🔗

Resets the behavior tree’s execution. Each running task will be aborted and the next tree execution will start anew. This method does not reset Blackboard.


void set_bt_instance(bt_instance: BTInstance) 🔗

Sets the BTInstance to play. This method is useful when you want to switch to a different behavior tree instance at runtime. See also BehaviorTree.instantiate.


void set_scene_root_hint(scene_root: Node) 🔗

Sets the Node that will be used as the scene root for the newly instantiated behavior tree. Should be called before the BTPlayer is added to the scene tree (before NOTIFICATION_READY). This is typically useful when creating BTPlayer nodes dynamically from code.


void update(delta: float) 🔗

Executes the root task of the behavior tree instance if active is true. Call this method when update_mode is set to MANUAL. When update_mode is not MANUAL, the update will be called automatically. See UpdateMode.