GoTree
A small Godot addon to easily implement node based behaviour trees.
GoTree provides a set of reusable behavour nodes that can be organized into behaviour trees in the scene tree. It also provides base scripts so you can create custom behaviours by extending GTLeaf, GTLeafCondition, or GTDecorator.
đ¤ Why use GoTree?
I made GoTree as light and barebones as possible. Behaviour trees can become large and complex so I decided to make the core nodes should be as simple and readable as possible so that it can be adapted to as many use cases as possible.
Each scripts is comment documented and should be fairly easy to figure out.
⨠What it includes
GoTreeRoot: the tree root that drives behaviour evaluation.GTSequence: ticks children in order and stops on the first non-success.GTSelector: ticks children until one succeeds or is running.GTRandomSelector: chooses a random child to tick each cycle.GTCondition: decorator that only ticks its child when a custom condition returns true.GTDelay: decorator that delays child execution for a configured duration.GTCooldown: decorator that blocks child execution until a cooldown expires.GTStatusInverter: decorator that inverts success/failure states.GTStatusOverrider: decorator that forces a fixed result regardless of the child.GTDebug: decorator that logs child ticks for development.GTLeaf: base leaf node for custom behaviour.GTLeafCondition: leaf node that returns success or failure from an overrideable condition.
đ§ How it works
- Place a
GoTreeRootnode under the scene node that owns the behaviour. - Set optional shared state using
actorandblackboardon the root. - Add a single child branch under
GoTreeRoot; only the first child is evaluated. - Use control flow nodes (
GTSequence,GTSelector,GTRandomSelector) to compose the tree. - Wrap branches with decorators to gate, delay, cooldown, debug, or alter results.
- Implement actions by extending
GTLeaforGTLeafCondition.
The root ticks the tree every tick_delay physics frames. That means the tree can run every physics frame or at a slower interval depending on the value of tick_delay.
âď¸ Installation
- Copy the
addons/go_treefolder into your Godot project. - Open
Project > Project Settings > Plugins. - Enable
GoTree.
đ Getting started
Example scene setup
- Add
GoTreeRootas a child of your agent or owner node. - Set
actorto the agent node (or use the root's parent node in code). - Add a control flow node as the first child of
GoTreeRoot. - Add leaf and decorator nodes under that control flow node.
Example behaviour tree
GoTreeRoot
ââ GTSequence
â ââ GTLeafCondition
â ââ GTDelay (delay = 0.5)
â â ââ GTLeaf
â ââ GTDebug (custom_debug_message = "Sequence ticked")
â ââ GTLeaf
Example custom leaf
extends GTLeaf
func tick(_delta: float, _actor: Node) -> Status:
if _actor.is_on_floor():
return Status.SUCCESS
return Status.FAILED
Example custom condition leaf
extends GTLeafCondition
func condition(_delta: float, _actor: Node) -> bool:
return _actor.health > 20
đĄ Use cases
- AI decision trees for NPCs and enemies
- Sequencing gameplay actions and abilities
- Cooldown, delay, and gating logic
- Behaviour prototyping and debugging
- Any state-driven logic that benefits from a tree structure
đ Notes
GoTreeRootonly evaluates its first child branch.GTLeafnodes should not have child nodes.GTDecoratornodes should have exactly oneGTNodechild.- Use
actorandblackboardonGoTreeRootto share data across the tree. tick_delayis measured in physics frames;1means every physics frame.
đ¤ Contributing
If you want to add new node types, improve documentation, or suggest enhancements, please open an issue. Feedback is welcome and appreciated!
Changelog for version GoTree v1.0
No changelog provided for this version.