Table of Contents
About The Project
I had code on sitting around on my hard drive for a Behavior Tree Editor That inspired me to create a bBehavior Tree Editor and write Articles about Behavior Tree and Using the Unity Editor UI Builder. It has been Pointed Out to me very polite and professional that this code is actually from the KIWI Coder.
Behavior Tree using UI Builder, GraphView, and Scriptable Objects in Unity 2021.3
This can be used as a template to build any type on Node Based Editor in Unity. i.e Dialog System or an AI Behavior Tree. If using for AI Behavior tree I would probably use Single Input Ports not Multiple. Even though the Nodes themselves are Scriptable Objects this can be changed and there is nothing that states that you have to use Scriptable Objects as the type for the nodes, this was just a decision that I made as it is easier to Bing the properties off the Node. Also there is nothing sating that the Nodes have to be stored in the Asset itself as I have done.
Behavior Tree is an execution tree (uses the Strategy pattern) and always starts with a Root Node. This will be so that the behavior tree knows where to start. Root Node has only one child. Now there are 3 basic main type of nodes Decorator, Composite Node and Action Node. Each Node can return one of three states Running, Success, or Failure. All nodes will be saved in Unity as Scriptable Objects. A Behavior tree will be a Scriptable Object containing all the Nodes in it.
- Has one child and is capable of augmenting the return state of it's child. This uses the Decorator pattern.
- Has a list of children and is the control flow of the behavior tree like switch statements and for loops. There are 2 types Composite Nodes the Selector and Sequence. This uses the Composite pattern.
- The Leaf of the tree, has no children, and is where all of the logic gets implemented.
To install this into your project for modifications Clone or Download the code from Git Hub into the Asset Folder of your project. Change the Folder From GraphView Behavior Tree to mach what you wold like. Edit all Files and change the NameSpace to match your new Folder Name. Do Not forget to change this in the UXML Documents as well. i.e "GraphViewBehaviorTree.Editor.SplitView" Delete the Runtime/james.lafritz.GraphViewBehaviorTree and Editor/james.lafritz.GraphViewBehaviorTree.Editor Assembly Definition Files, Or Edit/Replace them with your own.
To use Template as is Use the Package manager to Install package from Git Hub. see Creating custom packages for use in Unity
- In Unity open the package manager
- Go to Window->PackageManager
- Install this Package from git url
- Click the Plus Drop down
- Select "add package from git URL"
Behavior Trees In Unity](https://ktmarine1999.medium.com/behavior-trees-in-unity-20a738b5508c)
See the open issues for a list of proposed features (and known issues).
Distributed under the MIT License. See
LICENSE for more information.