Skip to content

01Pollux/Godot-BehaviourTree

Repository files navigation

GODOT_BTREE

A statically implemented Behaviour Tree logic in Godot 4.0+

Results

image

Installation

  1. Follow the detailed instruction on how to compile Godot.

  2. Use the main branch of Godot for Godot 4.0+.

  3. Copy the files (excluding /test/*) into a (/modules/behaviour_tree) in your Godot source folder.

  4. Compile like normally you would do.

Creating the visual Behaviour Tree

image

  1. Right click on folder / empty section.

  2. Press New Resources....

  3. Search for and add VBehaviourTreeResource.

Editor

image

  • Save: Saves the visual behaviour tree into the file.

  • Reload: Reload the visual behaviour tree from the file.

  • Save as Tree: Saves the visual behaviour tree as runtime behaviour tree.

Using the runtime Behaviour Tree

  • Check the /test/ in the github repository for the example.

  • Normally you would only need to load the runtime tree generated by visual editor and call get_behaviour_tree() on it, you could also load the visual behaviour tree but there is not reason to do so.

  • Initialize the tree by setting the object it should be targetting behaviour_tree.set_meta("bt_node_object", self) (this is optional if you're not using any node that uses bt_node_object meta data) and by setting other meta datas.

  • Initialize the nodes by calling behaviour_tree.initialize_tree().

  • Call behaviour_tree.execute_tree() in whatever logic / event you want.

Auto-initialized Tree

  • Create a node of type BehaviourTreeHolder.

  • Set the Target Node to it's parent or root. (It's advised to use root unqiue scene rather than using the main scene/subscene).

  • Set the Behaviour Tree to the resource in file or generate one by right clicking it. (It's advised to use a file generated behaviour tree to be able to debug the tree at runtime).

Adding custom nodes

  • Check the /test/ in the github repository for the example.

  • Create a simple json file and reference it from the target visual behaviour tree.

  • Each section represents a class name that extends to either BehaviourTreeCustomActionNode, BehaviourTreeCustomCompositeNode or BehaviourTreeCustomDecoratorNode.

  • For each section, it contains name, category and description.

Debugging Visual Behaviour Tree

  • Create a BehaviourTreeRemoteTreeHolder node.

  • Access and initialize the external remote tree by setting the vbehaviour_tree property with a VBehaviourTreeResource resource.

  • the tree will be visible by accessing the node in Remote tab and will be updated on each execute_tree call for tree resource.