top of page

Behavior Tree

Prior to this I had implemented somewhat dynamic StateMachines thru Strategy Patterns.
The idea was kind of what Behavior Tree's are and I was already leaning towards them!

Tree System

- Kitty Engine (own)

The base of my implementation is the usual thing, Composite, Leaf and Decorator nodes, all virtual ready to be adapted. And the root node holding a blackboard which can be passed along to the nodes.

Since we were using a Component System in our Game Engine, and some behaviors requiring data from other gameobjects. I implemented a "Awake" method as part of the base class TreeNode. This function provided a safe way of gathering information from the Game Scene.

Though I found it kind of annoying to attach childs and build the Behavior Tree thru code, I wanted to see the tree visually and remove the need of code it by hand.

This required a Tree Builder!

TreeNodeCode.png

Tree Builder

- Kitty Engine (own)

Since we already had a node scripting editor in place, the base fundamentals to build a Behavior Tree in our own Editor was already there. As my goal was to visually build the tree, I kept the editing part quite simple and let users choose from Composite, Leaf and Decorator nodes that held a dropdown menu for the specific type.

The last bit remaining was a "Tree Builder" class that could parse script nodes to actual Behavior Tree nodes.  To do this I wrote a Recursive function that parsed each node starting from the editor root node and downwards thru script pin connections. Generating an actual TreeNode and attaching child nodes.

The visual representation of a Behavior Tree was not pretty, but it gave us an clear overview of the flow and let us modify it easily!

BehaviourTree Editing.png
bottom of page