BTSubtree

Inherits: BTNewScope < BTDecorator < BTTask < BT

BT decorator that instantiates and runs a subtree within the larger tree.

Description

BTSubtree instantiates a BehaviorTree and includes its root task as a child during initialization, while also creating a new Blackboard scope.

Returns the status of the subtree’s execution.

Subtree blackboard variables can be mapped to the main tree blackboard plan variables. Check out mapping section in the inspector.

Note: BTSubTree is designed as a simpler loader, and does not support updating subtree at runtime. A custom subtree decorator is better suited:

extends BTDecorator
## MyCustomBranch

func _setup() -> void:
    var bt: BehaviorTree = load("res://...")
    var my_branch: BTTask = bt.get_root_task().clone()
    my_branch.initialize(agent, blackboard)
    add_child(my_branch)

func _tick(delta) -> Status:
    var child: BTTask = get_child(0)
    return child.execute(delta)

This allows for the BehaviorTree to load a specific behavior tree from a variable in the blackboard, or from some other location, and use that new behavior tree at runtime.

Properties

BehaviorTree

subtree


Property Descriptions

BehaviorTree subtree 🔗

A BehaviorTree resource that will be instantiated as a subtree.