Overview of Beehave for Godot
godot-4.xBeehaveTree node is attached to an actor (the node you want to control), and it runs its logic every frame tick, modifying the parent node based on the tree's execution.repository·godot-4.x·Indexed 25 days ago
https://github.com/bitbrain/beehaveA Godot Engine addon for creating AI systems using behavior trees. Beehave allows developers to build complex NPC behaviors and adaptive AI by integrating behavior trees directly into the Godot scene tree via the BeehaveTree node. It utilizes a node-based approach with status codes (SUCCESS, FAILURE, RUNNING) and provides specialized leaf nodes such as ConditionLeaf for state checks and ActionLeaf for performing tasks.
BeehaveTree node is attached to an actor (the node you want to control), and it runs its logic every frame tick, modifying the parent node based on the tree's execution.The Blackboard is a centralized repository used to store and share data between multiple nodes in a behavior tree. It prevents the need to pass variables directly to nodes and ensures data consistency across different game characters or objects.
By default, every BeehaveTree manages its own private blackboard instance. However, you can assign a custom Blackboard node from your scene tree to the blackboard property of a BeehaveTree to allow multiple trees to share the same data source.
Leaf nodes are the terminal nodes in a Beehave behavior tree. They have no children and represent the actual execution of logic. Unlike composite nodes or decorators that manage flow, leaf nodes interact directly with the game world.
There are two primary types of leaf nodes:
All leaf nodes must return one of three statuses: SUCCESS, FAILURE, or RUNNING.
Beehave uses a hierarchical tree structure composed of different node types to organize AI logic:
Move to position) or check specific conditions (e.g., Is health low?).Every node in a Beehave behavior tree returns one of three status codes that determine how the tree progresses:
RUNNING, it will be revisited on the next tick until it returns SUCCESS or FAILURE.You can monitor Beehave's performance directly within the Godot editor. Navigate to the Debugger panel at the bottom of the editor, select the Monitors tab, and scroll down to the beehave section.
Available global metrics include:
beehave/tree_id-process_time: The total process time per frame tick for the whole behavior tree.beehave/total_trees: The total number of Beehave nodes in the scene.beehave/total_enabled_trees: The number of active behavior trees in the scene.Action Leaf or Condition Leaf nodes to handle your specific mechanics.Use the Delayer decorator to create a delay between a trigger event and the subsequent reaction, allowing for anticipation or telegraphing in gameplay.
Structure:
Sequence
├── TriggerEvent
└── Delayer (seconds)
└── ReactToEventThe Memory Pattern uses the Blackboard to store information between ticks, allowing nodes to make decisions based on past events (e.g., remembering a player's last seen position).
Structure:
Sequence
├── Condition (Stores result in blackboard)
└── Action (Uses stored result)// SpotAndRememberPlayer.gd
class_name SpotAndRememberPlayer extends ConditionLeaf
func tick(actor: Node, blackboard: Blackboard) -> int:
var player = get_tree().get_first_node_in_group("player")
if player and actor.can_see(player):
// Remember where we saw the player
blackboard.set_value("last_seen_position", player.global_position)
blackboard.set_value("last_seen_time", Time.get_ticks_msec())
return SUCCESS
return FAILUREThe SimpleParallel node is used to execute exactly two children at the same time, following the logic: "While doing A, do B as well".
RUNNING.SimpleParallel node itself.SUCCESS or FAILURE, the SimpleParallel node immediately interrupts the secondary node and returns the primary node's result.SimpleParallel nodes can be nested to create complex behaviors, excessive nesting is not recommended as it can make behavior trees difficult to maintain.Use UntilFail to repeat a behavior continuously until it returns a failure status. This is ideal for automating repetitive tasks like resource gathering.
Structure:
UntilFail
└── BehaviorToRepeat