
Behavior Trees and Blackboards
A tree to decide how we should behave, a blackboard to remember it!
Welcome to Chapter 2, Behavior Trees and Blackboards. This is where things start to get a bit more interesting because we will learn how to use the two main Unreal AI Framework structures. First, we will look at Behavior Trees and learn all about their principal components, such as tasks, decorators, and services. Next, we will learn about Blackboards and how to integrate them with Behavior Trees. After we have covered this, will be able to set up AI controllers that use Behavior Trees, which is key in implementing the rest of the techniques in this book.
As you may notice, there is a pattern in which we first learn a little bit about the theory, and then we jump straight into practice to understand how it all works. This is a pattern that we will follow in each chapter. So, let's get going.
In the field of Decision-Making, there are many mathematical structures that can be used. Finite State Machines (FSMs) are an easy, yet powerful example of systems that are able to make complex decisions. However, in the world of Artificial Intelligence for games, there is another structure that can also be used by non-AI experts: Behavior Trees.
As a result, one of the design choices of Unreal Engine is that it has built-in support for Behavior Trees, and is actually part of the main core of the AI Framework. This does not imply that you cannot implement other decision-making processes or structures, but using the built-in support for Behavior Trees will greatly benefit your team's budget (in terms of time). So, before you implement a different Decision-Making structure in Unreal, think twice about whether that is a good decision (of course, a Behavior Tree might not be optimal for your game, but keep in mind that they have built-in support and might be a great time-saver). Nonetheless, you can still implement sub-structures within the Behavior Tree to extend its functionality, but do not rush too much; first, let's learn about the basics of Behavior Trees.
In particular, in this chapter, we will learn about the following topics:
- What a Behavior Tree is, both in broader terms and within the Unreal Context.
- How a Behavior Tree works within Unreal, including its different components and how they interact with the tree
- What a Blackboard is and how it can be used to store data for the Behavior Tree
- How to start running a Behavior Tree by using the AI Controller, both in Blueprint and C++
So, let's dive in!