Behaviour trees: Looking for a way in

I’ve been using finite state machines for a while. I absolutely love them and use them whenever I can.

I’ve never tackled any in-depth AI before, and I’ve read that behaviour trees are better than finite state machines when it comes to AI.

I’ve tried to google how to script behaivour trees but I was just inundated with assets for visual scripting. I really want to sharpen my programming skills, so I want to learn how to create my own behaviour tree from scratch -even if it’s only very basic. Visual scripting seems like a bit of crutch.

Can someone point me to some tutorials/books for getting started? Is it anything like programming a finite state machine?

p.s. sorry about the tags. There was nothing for AI or behaviour trees.

I highly recommend Mat Buckland’s “Programming Game A.I. by example” as an introduction to many aspects of game A.I. including FSMs, fuzzy logic, steering behaviours, task-planning and behaviour management. The examples are in C++ so you’ll have to translate them before they can be used in Unity, but that’s no bad thing to test your understanding.

Behaviour Trees are indeed much more suited for AI than FSM, specially when your AIs are complex. FSMs just become unmanageable when the number of states is big; modifying big FSMs is very likely to introduce bugs. Whereas Behaviour Trees are much more flexible, are easier to modified and scale very well as your AIs grows in complexity.

If you are a programmer and not appealed by node-based visual editors, you might be interested by Panda BT (www.pandabehaviour.com). It’s a tool more oriented towards programmers and based on scripts (yet the execution of the tree can be visualized at runtime); you define your tasks as C# functions, then use them while writing BT scripts to define your behaviour trees.

Behaviour Tree is relatively young compared to FSM. There are far less ressources available about BT. As a starting point, I’d suggest these resources to get a grasp what behaviour trees actually are.

Once you are familiar with some BT basic concepts, using Panda BT should be straight forward. Then have a look and toy around with the examples provided in the package.

I’m the author of Panda BT, I’d be glad to help if you have any question. You’re welcome to ask them on this thread.