How to create a simple behaviour tree in Unity/C#

Let’s see how to implement a basic behaviour tree to make a simple guard AI!

Mina Pêcheux
Geek Culture
Published in
16 min readNov 2, 2021

--

🚀 Find all of my Unity tutorials on Github!

This tutorial is available either in video format or in text format — see below :)

Get the scripts and assets for this tutorial on my Github :)

Wait — what about FSMs?

In a previous tutorial, I talked about finite state machines — aka FSMs — and I discussed how this pattern can help you implement well-organised and well-structured behaviour system, as long as this behaviour isn’t too complex.

In a follow-up episode, we saw how hierarchical finite state machines can mitigate some of the downsides of the FSMs by introducing inheritance and higher-order abstract states.

But the fact is that, when you try and model a more complex behaviour, FSMs will eventually come short. Chances are that, if you work on a really advanced AI system, or just on a player system that…

--

--

Mina Pêcheux
Geek Culture

I’m a freelance full-stack web & game developer. I’m passionate about topics like CGI, music, data science and more! Find me at: https://minapecheux.com :)