SamSuka
naelstrof
naelstrof

patreon


Unity Visual Behavior Tree Implementation

I used to hate visual programming. Things like Unreal Blueprints are dreadfully slow and very difficult to read. While also being very awful for versioning tools like git.

Though I realized that visual node-based programming is a tool like any other, and for some tasks it's extremely good. (Shader programming, dialogue trees, and maybe AI decision making for example!)

I found this sweet article done by Chris Simpson and it seems like a reasonable way to visualize AI decision making.

I found a lot of Behavior tree implementations, but none of them supported a visualization component. 

In general I would advise to NOT re-invent the wheel, it takes a long time, it's prone to mistakes, and someone probably already encountered and fixed issues that you could have.

Though I totally reinvented the wheel and created a new behavior tree system so I could ensure it supported visual programming. (What I fool I am!!)

Using XNode, it's extraordinarily easy to create some nodes and hook them up. Though XNode uses Scriptable Objects (a global static structure) in order to store the nodes and their connections.

Each AI needs a way to store their state, and only use the static structure for the logic. Instead of re-instantiating the graph for each AI, I opted to save their state within a context (something a behavior tree needs anyway to transfer data).

Using C#'s Attribute sugar, I'm able to mark variables as needing to be saved/loaded in the context each time the node is ran.

After a week of spooky serialization issues, context switching problems, and other hard-to-debug issues-- I finally got it!

Here's the above node graph in action:

And below is within KoboldKare.

Each Kobold has its own context and internally uses a visual graph to figure out what to do!

Now I just need to make more complex nodes and then Kobolds will start seeming really intelligent-- maybe.

Since there's a lack of XNode supporting behavior tree implementations, I've packed up and published my implementation here:  https://github.com/naelstrof/UnityBehaviorTreeImplementation 

Feel free to tell me how horrible it is! Hopefully someone will find it useful. I'm planning on adding a visualization so I can see what a certain AI agent is thinking while their graph processes. 

This will lead to enemies, NPCs, and Kobolds all sharing logic for getting targets and doing actions. I'm real excited about it!


More Creators