Hands-On Artificial Intelligence with Unreal Engine

3.5 (2 reviews total)
By Francesco Sapio
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Making the First Steps in the World of AI

About this book

Learning how to apply artificial intelligence ( AI ) is crucial and can take the fun factor to the next level, whether you're developing a traditional, educational, or any other kind of game. If you want to use AI to extend the life of your games and make them challenging and more interesting, this book is for you.

The book starts by breaking down AI into simple concepts to get a fundamental understanding of it. Using a variety of examples, you will work through actual implementations designed to highlight key concepts and features related to game AI in UE4. You will learn to work through the built-in AI framework in order to build believable characters for every game genre (including RPG, Strategic, Platform, FPS, Simulation, Arcade, and Educational). You will learn to configure the Navigation, Environmental Querying, and Perception systems for your AI agents and couple these with Behavior Trees, all accompanied with practical examples. You will also explore how the engine handles dynamic crowds. In the concluding chapters, you will learn how to profile, visualize, and debug your AI systems to correct the AI logic and increase performance.

By the end of the book, your AI knowledge of the built-in AI system in Unreal will be deep and comprehensive, allowing you to build powerful AI agents within your projects.

Publication date:
April 2019


Chapter 1. Making the First Steps in the World of AI

From the bronze giant Talos, to Symbolic Systems and Neural Networks: how AI has been shaped and used in video games.

Welcome, reader, to the beginning of our journey in Artificial Intelligence, or AI for short. Have you ever wondered about how those hard-working peons in Warcraft explore complicated maps? Or, how those perky ghosts in Pac-Man can get you wherever you are? Or perhaps how your opponents in Final Fantasy optimize their attacks to slaughter your team?

A screenshot from Final Fantasy XV [Square Enix, 2016] during a battle.

Then you've come to the right place!

In this chapter, we will explore the prerequisites to becoming an AI game developer and how AI is used in the game development pipeline. Then, we will take a look at the history of AI in general and in video games, and learn how the conjunctive effort of many brilliant minds built AI as we know it today. Afterwards, we will discuss the AI Framework underneath the Unreal Engine, since this book will focus on Unreal.

Finally, we will plan our journey and get a general overview of the topics that the different chapters in this book deal with.


Before starting...

... I'd like to reply to some questions that some of you might already have.

Does this book take into account Blueprint or C++?

This book will explain both, so don't worry.

If you don't know C++, you can follow along with the Blueprint part of this book, and if you so wish, you can try the C++ one.

If, on the other hand, you are a programmer that prefers C++, then don't worry! This book will explain how to deal with AI in Unreal using C++.

There are so many books around about AI, why should I choose this one?

Different books explain different aspects of AI, and often they are not mutually exclusive, but rather they complement each other.

However, the major point of interest of this book is that it is a good compromise between the theory of the different AI systems that are present in Unreal and practical applications, since the whole book is full of concrete examples.

Does this book provide a test project/materials to work on?

Absolutely, yes. You will be able to download the content for this book from the following link: http://hog.red/AIBook2019ProjectFiles (the link is case-sensitive).


I am already using the Unreal Engine for Artificial Intelligence, is this book good for me?

This all depends on your level of knowledge. In fact, in the first part of this book, we will talk mainly about the AI framework that's built into the Unreal Engine and how to use it. This is probably the part you are more familiar with if you have had some experience with Unreal for AI. However, this book will dive deep in these topics, that even an expert could find some useful tips. The second part, instead, will discuss some debugging methods for Game AI and will also explain how to extend them (mainly with C++). Feel free to have a look at the outline, and decide if this book suits you.

I am already using another game engine, is this book still good for me?

Well, as much as I'd like to say that this is a general book about AI, it isn't—at least not completely. Although the main focus will still be toward the main concepts of AI, we will look at implementing them in Unreal. However, this book will heavily rely on the built-in AI framework in Unreal. Thus, I encourage you to read more generalized books about AI to get a better understanding. On the other hand, you can always try. Maybe, by understanding some concepts here, other books will be easier to read and you will be able to transfer this knowledge into the game engine of your choice.

I'm a student/teacher, is this book suitable for teaching in class?

Absolutely, yes. I know how important it is to find good resources when teaching a class, and I'm writing this book with this intention in mind. As a result, regardless of whether you are a student or a teacher, you will find a section at the end of each chapter with some exercises that you can improve your skills this (or propose them to your students, if you are a teacher). Also, you can find some more integrative material here: http://hog.red/AIBook2019LearningMaterial (the link is case-sensitive).

Is this book going to cover everything, everything, and everything about AI in Unreal and all its systems?

Well, despite my best efforts to describe each of the systems in great detail, covering everything is an impossible task, due also to the complexity of such big engine. However, I'm confident to say that this book covers most of the aspects related to each AI system within the Unreal Engine, including how to extend the built-in systems and how to efficiently perform debugging. Thus, I can certainly say that this book is very comprehensive.



Since this book is targeted at people who are getting started with AI in game development, I will not assume any prior/background knowledge in AI. However, please take the following into account:

  • Blueprint users: You should be familiar with Blueprint programming, and know how a Blueprint graph works in general.
  • C++ users: You should be familiar with programming, especially with the C family languages (such as C, C#, C++, or even Java), and in particular with C++, since it's the language that Unreal Engine uses. Being familiar with the Unreal Engine C++ API is a great bonus, although not strictly required. So, even if you are not a master, don't worry—follow along and you will learn.

Also, it would be great if you had some knowledge about vector math and physical kinematic principles – at least the ones commonly used in video games. Either way, in case you are rusty on those, don't worry too much, since it is not required for this book; however, it is nice to have if you're looking for a job as an AI Developer.


Installing and preparing the software

Before you continue reading, let's install the software we need. In particular, we will need Unreal Engine and Visual Studio.

Unreal Engine

Let's talk about Unreal Engine. After all, this is a book about how to develop game AI within this wonderful game engine.

Unreal Engine is a game engine that was developed by Epic Games. It was first released in 1998, and nowadays it is one of the most used (open) game engines (alongside Unity) due to its powerful features. The following screenshot shows the main interface of Unreal Engine:

Screenshot of the main interface of Unreal Engine

We need to have the latest version of Unreal Engine installed. You can find it by visiting https://www.unrealengine.com/en-US/what-is-unreal-engine-4 . Unless you took Unreal Engine from the source code (https://docs.unrealengine.com/en-us/Programming/Development/BuildingUnrealEngine), you will have the Epic Launcher installed. If you are a Blueprint user, and do not intend to use C++, then this is enough for you. If, on the other hand, you will be using C++, you will need to perform a couple of extra steps.

When installing the Engine, you will need to check some options (if you are using C++). In particular, we need to check that we have both "Engine Source" and "Editor symbols for debugging", as shown in the following screenshot:

By doing so, we will be able to navigate through the C++ Engine Source and also have a full stack of calls in the case of a crash (so you will know what went wrong). 

Visual Studio

You won't need this if you are using Blueprint—this is for C++ users only. 

In fact, we will need an IDE to edit our C++ code. We are going to use Visual Studio, since it's well-integrated with Unreal. You will be able to download Visual Studio Community Edition for free through the official website, https://www.visualstudio.com, or from https://visualstudio.microsoft.com/vs/.

You may also find this short guide on how to set up Visual Studio so that it works with Unreal Engine useful: https://docs.unrealengine.com/en-us/Programming/Development/VisualStudioSetup.

Once you have everything installed and ready to go, we can continue with the rest of this chapter.


If you are a MacOS user, there is a version of Visual Studio for MacOS. You can use that one. Alternatively, you might be able to use XCode.


Becoming an AI Game Developer

Ever dreamed of becoming an AI Game Developer? Or maybe just be able to write "intelligent" programs? Then this book is for you!

However, I need to advise you that this is no easy task.

Game development and design are some of the most extensive works of art around. This is due to a large amount of expertise that is required to bring a game to life. You can get an idea of this by just looking at the final credits in a game. They are endless and contain names of people who have dedicated a lot of their time to the game in various roles. AI development is a central part of this big process, and it requires years to master it, like most things in life. As such, iteration is key, and a great place to get started in this book.

What it means to be an AI Game Developer

First of all, you will need to master maths, physics, and coding. Also, you will mostly probably work in an interdisciplinary team, which includes artists, designers, and programmers. In fact, you will probably work with existing proprietary software technology, and it's required that you are able to build new technology to fulfill the project's technical requirements. You will be asked to research coding techniques and algorithms so that you keep yourself up to date on technological developments and advancements in the game industry and to identify technical and developmental risks/obstacles and generate solutions to overcome identified risks.

On the other hand, you will be able to give life to characters and entities in video games. After all the frustrations that you might go through, you will be the first one to assist, or better, generate an intelligent behavior in games. It takes time and is quite challenging, so don't be too hard on yourself in the early stages. Once you achieve some real AI in your game that can think on its own, this is an achievement worthy of rewarding yourself for.

For beginners in AI, this book will help you set the first stones toward that goal. For experts, this book will provide a useful guide to refresh the different AI systems in Unreal, and explore in-depth features that might help you in your work.

AI in the game development process

The game development pipeline might vary a lot, depending on which studio you visit, but all of them lead to the creation of a video game. This is not a book about pipelines, so we won't explore them, but it's important to have a rough idea of where AI is collocated.

In fact, AI intersects with many parts of the game development pipeline. Here are some of the main ones:

  • Animation: It might surprise some of you, but there is a lot of research going on regarding this topic. Sometimes, animation and AI overlap. For instance, one of the problems that developers need to solve consists of how we can procedurally generate hundreds of animations for characters, which can behave realistically, and also how they interact with each other. In fact, solving the inverse kinematic (IK) is a mathematical problem, but which of the infinite solutions to choose to achieve a goal (or just to provide a realistic look) is an AI task. We won't face this specific problem during this book, but the last chapter will provide pointers to places where you can learn more about this.
  • Level Design: If a game automatically produces levels, then AI plays an important role in that game. Procedural Content Generation (PCG) in games is a hot topic at the moment. There are games that are entirely based on PCG. Different tools to procedurally generate height maps can help Level Designers achieve realistic looking landscapes and environments. This is indeed a wide topic to explore.
  • Game Engine: Of course, inside the game engine, there are many AI algorithms that come into play. Some of these are specific for agents, while others just improve the engine's features and/or tasks. These represent the most vast category, in which they can vary from simple algorithms to adjust a Bezier curve based on the context, to implementing behavior trees or finite state machines for animations. Under the hood, there is a lot going on here. We will explore some of these concepts in this book, but the message to take home is that an algorithm can be adapted to solve similar problems in different fields. In fact, if Finite State Machines (FSMs) are used to make decisions, why not use them to "decide" which animation to play? Or why not even handle the whole game logic (i.e. the blueprint visual scripting in Unreal Engine)?
  • Non-Player Characters (NPCs): This is the most visible example of using AI in games, and this is also the most obvious AI to the Player (we will explore more about the relationship between the AI and the player in Chapter 14, Going Beyond). This is what most of this book is focused on; that is, from moving the character (for instance, with a Pathfinding Algorithm) to making decisions (i.e. with Behavior trees), or collaborate with other NPCs (multi-agent systems).

Unfortunately, we don't have the space to deal with all of these topics in this book. Therefore, we will just be focusing on the last part (NPCs), and explore the AI Framework that's built into Unreal.


A bit of history

Before venturing on our journey, I believe that having a general overview of the history of AI and AI in games might be beneficial. Of course, you can skip this part if you are a more hands-on type of person who cannot wait to getting down to programming AI.

What is AI?

This is a very interesting question, which doesn't have a unique answer. In fact, different answers lead to different aspects of AI. Let's explore some (of many) definitions that have been given by different scholars (in chronological order).

Actually, Russell and Norvig, in their book, organized these specific definitions into four categories. Here is their schema:

Russell and Norvig's four categories. Top-left: "Systems that think like humans". Top-Right: "Systems that think rationally". Bottom-Left: "Systems that act like humans". Bottom-Right: "Systems that act rationally".

We don't have the time to go into detail about the question "What is AI?", since this could fill up another book on its own, but the last chapter of this book will also include some philosophical reference where you can expand your knowledge on this topic.

A glance into the past

It might come unexpected to some of you, but the story of AI started well before computers. In fact, even ancient Greeks hypothesized the existence of intelligence machines. A famous example is the bronze giant Talos, who protected the city of Crete from invaders. Another is the golden helpers of Hephaestus, who helped God in his volcano forge along with the Cyclops. In the XVII century, René Descartes wrote about automatons that could think, and believed that animals were do different from machines, which could be replicated with pulleys, pistons, and cams.

However, the core of this story starts in 1931, when the Austrian logician, mathematician, and philosopher Kurt Gödel proved that all the true statements in the first-order logic are derivable. On the other hand, this is not true for higher order logics, in which some true (or false) statements are unprovable. This made first-order logic a good candidate to automate derived logical consequences. Sounds complicated? Well, you can imagine how that sounded to the ears of his traditionalist contemporaries.

Photo of Alan Turing at the age of 16

In 1937, Alan Turing, an English computer scientist, mathematician, logician, cryptanalyst, philosopher, and theoretical biologist, pointed out some of the limits of "intelligent machines" with the halting problem: it is not possible to predict a-priori if a program will terminate unless it is actually run. This has many consequences in theoretical computer science. However, the fundamental step happened thirteen years later, in 1950, when Alan Turing wrote his famous paper "Computing Machinery and Intelligence", in which he talked about the imitation game, nowadays mostly known as "The Turing Test": a way to define what an intelligent machine is.

In the 1940s, some attempts were made to emulate biological systems: McCulloch and Pitts developed a mathematical model for a neuron in 1943, and Marvin Minsky created a machine that was able to emulate 40 neurons with 3,000 vacuum tubes in 1951. However, they fell into the dark.

From the late 1950s through to the early 1980s, a great portion of AI research was devoted to "Symbolic systems". These are based on two components: a knowledge base made out of symbols and a reasoning algorithm, which uses logical inference to manipulate those symbols, in order to expand the knowledge base itself.

During this period, many brilliant minds made significant progresses. A name worth quoting is McCarthy, who organized a conference in Dartmouth College in 1956, where the term "Artificial Intelligence" was first coined. Two years later, he invented the high-level programming language LISP, in which the first programs that were able to modify themselves were written. Other remarkable results include Gelernter's Geometry Theorem Prover in 1959, the General Problem Solver (GPS) by Newell and Simon in 1961, and the famous chat-bot Eliza by Weizenbaum, which was the first software that, in 1966, could have a conversation in natural language. Finally, the apotheosis of symbolic systems happened in 1972 with the invention of PROLOG by the French scientist Alain Colmerauer.

Symbolic systems led to many AI techniques, which are still used in games, such as blackboard architectures, pathfinding, decision trees, state machines, and steering algorithms, and we will explore all of them throughout this book.

The trade-off of these systems is between knowledge and search. The more knowledge you have, the less you need to search, and the faster you can search, the less knowledge you will need. This has even been proven mathematically by Wolpert and Macready in 1997. We will have the chance to examine this trade-off in more detail later in this book.

At the beginning of the 1990s, symbolic systems became inadequate, because they proved hard to scale to larger problems. Also, some philosophical arguments arose against them, maintaining that symbolic systems are an incompatible model for organic intelligence. As a result, old and new technologies have been developed that were inspired by biology. The old Neural Networks were dusted off from the shelf, with the success of Nettalk in 1986, a program that was able to learn how to read aloud, and with the publication of the book "Parallel distributed processing" by Rumelhart and McClelland in the same year. In fact, "back-propagation" algorithms were rediscovered, since they allow a Neural Network (NN) to actually learn.

In the last 30 years of AI, research took new directions. From the work of Pearl on "Probabilistic reasoning in intelligent systems", probability has been adopted as one of the principal tools to handle uncertainty. As a result, AI started to use many statistical techniques, such as Bayesian-nets, Support Vector Machines (SVMs), Gaussian processes, and the Markov Hidden Model, which is used widely to represent the temporal evolution of the states of a system. Also, the introduction of large databases unlocked many possibilities in AI, and a new whole branch named "Deep Learning" arose.

However, it's important to keep in mind that, even if AI researchers discover new and more advance techniques, the old are not to be discarded. In fact, we will see how, depending on the problem and its size, a specific algorithm can shine.

AI in games

The history of AI in video games is as interesting as what we talked about in the previous section. We don't have the time to go through it in detail and analyze every single game and how each one of them contributed to the field. For the most curious of you, toward the end of this book, you will find other lectures, videos, and books where you can dive deeper into the history of AI in games.

The first form of AI in video games was rudimental and used in games like Pong [Atari, 1972], Space Invaders [Midway Games West, Inc., 1978], and so on. In fact, beyond moving a paddle to try and catch a ball, or moving aliens toward the player, there wasn't much more we could do:

A screenshot of Space Invaders Midway Games West, Inc., 1978], in which a rudimental form of AI is used to control the aliens

The first renowned game that used a noticeable AI was Pac-Man [Midway Games West, Inc., 1979]. The four monsters (later named ghosts due to a flickering port in the Atari 2600) used an FSM to chase (or flee from) the player:

A screenshot from the game Pac-Man Midway Games West, Inc., 1979], in which the four monsters use an FSM trying to catch the player

During the 1980s, AI in games didn't change much. It was only with the introduction of Warcraft: Orcs & Humans [Blizzard Entertainment, 1994] that a pathfinding system was successfully implemented in a video game. We will explore the Navigation system in Unreal in Chapter 3, Navigation:

A screenshot from Warcraft: Orcs Humans Blizzard Entertainment, 1994], in which the units (orc peons and grunts in this screenshot) use pathfinding algorithms to move in the map

The game that probably started to sensitize people about AI was Goldeneye 007 [Rare Ltd., 1997], which showed how AI could improve gameplay. Although it was still relying on FSMs, the innovation was that characters could see each other, and act accordingly. We will explore agent-awareness in Chapter 5, Agent Awareness. This was a hot topic at the time, and some games made it the main game mechanic, such as Thief: The Dark Project [Looking Glass Studios, Inc., 1998]:

A screenshot from Goldeneye 007 Rare Ltd., 1997], which has changed how people perceive AI in video games

and Metal Gear Solid [Konami Corporation, 1998]:

A screenshot fromMetal Gear Solid [Konami Corporation, 1998],

Another hot topic was modeling a soldiers' emotions during battles. One of the first games that implemented an emotional model was Warhammer: Dark Omen [Mindscape, 1998], but it was only with Shogun: Total War [The Creative Assembly, 2000] that these models were used with extreme success with a large number of soldiers without performance issues:

A screenshot from Warhammer: Dark Omen, one of the first games that used an emotional model for soldiers


A screenshot from Shogun: Total War. The emotional model of the soldiers were more sophisticated than the one in Warhammer: Dark Omen, and yet it was used successfully with many soldiers

Some games even made AI the core of the gameplay. Although one of the first games to do so was Creatures [Cyberlife Technology Ltd., 1997], the concept is more evident in games like The Sims [Maxis Software, Inc., 2000] or Black and White [Lionhead Studios Ltd., 2001]:

A screenshot from The Sims. A Sim (the character) is cooking, which is part of a complex behavior piloted by AI in the game.

In the last 20 years, many AI techniques have been adopted and/or developed. However, if the game doesn't require an advanced AI, you will probably find FSMs, still being broadly used, along with Behavior trees, which we will start exploring soon in Chapter 2, Behavior Trees and Blackboards.

AI in games – Industry and Academia

When it comes to comparing AI that's applied to video games, both in Academia and in the Industry, there is a big discrepancy. I would say that there was almost a fight between the two. Let's have a look at the reasons behind this. In fact, they have very different goals.

Academia wants to create AI agents for games that think intelligently to act in the environment and interact with the player.

On the other hand, the game industry wants to create AI agents for games that seem to think intelligently to act in the environment and interact with the player.

We can clearly notice that the first leads to a more realistic AI, whereas the second leads to a more believable AI. Of course, commercial games are more worried about the latter rather than the former.

We will explore this concept in more detail in Chapter 14, Going Beyond, when we talk about the psychology and game design involved in creating an AI system for games. In fact, to achieve a believable behavior, you often need to try and be realistic as well.

However, in more formal terms, we can say that game AI falls in the category of weak AI (opposite to strong AI), which focuses on solving a specific task or problem intelligently, rather than develop a consciousness behind it. In any case, we won't venture further into this.


Planning our journey

It's finally time to start planning our journey, before jumping into the next chapter.

Technical terminology

Since, for some of you, this is your first journey into AI, it's important that you have a small glossary of the technical terms that are used throughout this book (and in general, in AI). We have already encountered some of these in the past few pages:

  • Agents are systems that are capable of autonomous reasoning toward solving a specific set of goals.
  • Backward Chaining is the process of tracing the cause of a problem by working backwards.
  • Blackboard is an architecture for exchanging data between different agents, and sometimes even within the agent itself (especially in Unreal).
  • Environment is the world where an agent lives. For instance, the game world is the environment of an NPC from the same game. Another example is a chess board, which represents the environment of a system that plays chess against humans (or other systems).
  • Forward Chaining, opposite to Backward Chaining, is the process to work forward to find the solution to a problem.
  • Heuristic is a practical approach to problem-solving, which does not guarantee to be optimal, nor sufficient for immediate goals. Heuristic methods are used when finding the optimal solution to a problem is impractical (if not impossible), in order to find a satisfactory solution. They can be thought of as mental shortcuts to lighten cognitive load during a decision-making process. Sometimes, it can represent the knowledge of an agent based on his/her past experience (although this is often given a-priori). The term "Heuristic" derives from ancient Greek, with the meaning of "find" or "discover".


For a more extensive glossary, you can have a look at the one on Wikipedia. Here is the link: https://en.wikipedia.org/wiki/Glossary_of_artificial_intelligence.

The bottom-up approach

Usually, when a system is built or studied, there are two main approaches: top-down and bottom-up. The former starts from the high-level structures of the system and proceeds gradually into the granular details of the system. The latter starts from the basics and proceeds to create more complex structures that depend on the previous ones. Both approaches are valid, but, as a matter of preference, I chose the bottom-up approach to introduce the topics of this book.

In fact, we will start with how an agent can move, then understand how it can perceive, and finally use this data to make an informative decision or even come up with a plan. This is reflected in the structure of this book and its parts.

The agent schema

Since, during this book, we will be going through the different parts of how an AI agent can perceive, move, plan, and interact with its surroundings, it will be useful to draw a schema for this. Of course, there can be many other schemas, and they are all equally valid, but I believe that this one is particularly useful for getting started with AI Game Development:

The Agent model that we are going to use in this book

Since we chose a bottom-up approach, we should read the schema from the bottom. We will refer to this in more formal terms as our agent model.

First, we can see that the agent always exchanges information with the Game World, which includes geometry, physics, and animations, but also abstractions of it. This information is used at all the levels of our agent model.

From the bottom, we can see that our first concern is how to move in the environment. This is a process that can be split into Motion and Pathfinding (Chapter 3, Navigation). Going up the chain, we can see that the agent perceives the world (Chapter 4, Environment Query System, and 5, Agent Awareness), and, based on this perception, the agent can make a decision (Chapter 2, Behavior Trees and Blackboards). Sometimes, making the best decision at that moment in time, might not lead to a better result in the long run, and so the agent should be able to plan ahead. Often, in video games, an AI system (which is not necessarily an NPC) can control more than one character, and, as a result, it should be able to coordinate a group of characters. Finally, the agent might need to collaborate with other agents. Of course, we won't be able to go deep into each topic in this book, but feel free to take a look online so that you can dive deeper into certain topics.

One final remark: Often, AI in games doesn't use all of these levels at once; some implement just one of them, or mix them up. However, it's important to keep in mind how things are structured before you start playing with them.

Unreal Engine AI Framework

Despite other game engines, which just give you rendering capability, Unreal Engine comes with many things implemented (and extended through plugins). This doesn't mean that making a game is easier, but rather that we have more tools to develop one.

As a matter of fact, Unreal implements many tools for Artificial Intelligence as well. While we explore them, we can create a schema of these tools and how they correlate to each other. So, let's try to just understand at which level we are going to operate. This means scratching the surface of the Unreal Game Play Framework (you can find more information about this here: https://docs.unrealengine.com/en-us/Gameplay/Framework).

There is a Controller Class, which can be divided into two subclasses. The first one is a Player Controller; as the name suggests, it offers an interface between the game and the player (of course, it is not covered in this book, since we will focus on AI and not general Gameplay). The second class is the AIController, which, instead, offers an interface between our AI algorithms and the game itself.

The following diagram shows these and how they interact with one another:

Both kinds of controllers can possess a Pawn, which can be considered a virtual avatar. For the player, this may be the main character; for an AIController, a Pawn can be the enemy who wants to defeat the player.

In this book, we will focus only on the AIController, and all the tools around and beneath it to bring our AI to life (we will not cover the dotted sections in the preceding diagram). We will understand what I mean by this at a later stage, but the key concept is that we are going to operate at the level of an AIController.


If you are already a bit familiar with C++ and Unreal, you can have a look at its class, which is defined in the AIController.h file, to learn a bit more about this controller.

A sketch of our journey

Now that we have a rough idea of the schema we are going to use, let's break down what we will cover in this book, more or less in the order we will face the topics (I said more or less, because some topics are spread over more than one chapter, and they need to iterate once our knowledge of AI has been expanded).



However, you can think of this book as being divided into three parts:

  • Chapters 2-7: A description of the different built-in AI systems
  • Chapters 8-10: A concrete example of how to use the AI systems we explored in the previous chapters
  • Chapters 11-13: A description of the different debugging methods for Game AI (since I believe that this part is equally important that knowing the systems themselves)

Let's talk about what we will be covering in this book in detail.

Decision-making with Behavior Trees (chapters 2, 6, 8, 9, and 10)

Once the agent can perceived the world around it, it needs to start making decisions, which have consequences. Some decision-making processes might become so complicated that the agent needs to come up with a proper plan to successfully achieve a goal.

The built-in Unreal Engine framework for AI rotates around Behavior Trees, which occupy a significant part of this book. Of course, this doesn't preclude the possibility to implement other AI systems on your own for decision-making in Unreal, but, by choosing Behavior Trees, you will have a strong set of tools ready to go, which we will explore in detail in this book.

Navigation (chapters 3 and 7)

Unless the game is discrete or turn-based, each AI agent needs to move around its own environment in a continuous fashion. Unreal provides a strong Navigation System that lets your AI Agents navigate easily within the environment, from falling to jumping, from crouching to swimming, to different kind of areas and different types of agent.

This system is so huge that it will be hard to cover it all, but we will do our best to cover everything you need to get started in Chapter 3, Navigation.

Environment Query System (chapters 4 and 12)

The Environment Query System (ESQ) can gather information from the environment surrounding the agent, thus allowing the agent to make decisions accordingly. This book dedicates a whole chapter to this system. In fact, it lies between Chapter 5, Agent Awareness, and Decision Making, and it is a great resource that's already built into Unreal.

Agent Awareness (chapters 5 and 12)

Agent Awareness (or Perception) deals with the capacity to give senses to the AI agents. In particular, we will cover sight, which is the most common and widely used, but also hearing and smell.

Moreover, we will start to explore how this data will be used in higher level structures so that the agent can act accordingly.

Crowds (chapter 7)

When you have many AI agents within your map, the environment becomes easily overcrowded, and the various agents might interfere with each other. Crowds Systems allow you to control large sets of AI Agents (while they can keep an individual behavior) so that they can avoid each other.

Designing Behavior Trees (chapters 8, 9, and 10)

It is not enough for an AI developer to know how a Behavior Tree works: he/she needs to know how to design them. In fact, most of your job is about creating an abstract system that coordinates all your AI agents, and only after that will you spend the rest of the time implementing it. Therefore, we will cover a single and large example of how to design, create single pieces, and build a whole Behavior Tree from scratch.

Debugging methods for Game AI (chapters 11, 12, and 13)

Once you have learned about all the different AI systems, you can start to experiment on those or program a game, but how do you understand if your AI is doing what you have planned and/or is performing well? Debugging methods are key in any software, but in Game AI, you will also need visual debugging. As such, Unreal Engine comes with many debugging methods (including some that are specific for AI), and I strongly believe that being knowledgeable of those is very important. You will not only learn the tools, but also how to extend them as per your needs.

Going beyond (chapter 14)

This last section of this book will explore some exciting ideas and innovation that's currently going on in the AI world, and will give you the inspiration to continue your wonderful journey. I will introduce some of the ongoing research on AI that's being applied to games, and how this can ultimately benefit your game. Being aware of new technologies and algorithms is key in this field so that you are always up to date.

Enabling AI for C++ users

In case you are following this book as a C++ user, when you write C++ code within your project (or a specific module of your project or plugin), you will need to ensure that you add the right dependencies so that you have access to the AI systems, otherwise you will end up with compilation errors. We will look at this in more detail in the next chapter when we create a project for inserting all the code we will produce in this book. However, here is the line of code to insert/modify code in the .cs project file (the part of code in bold is required for AI to work):

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "GameplayTasks", "AIModule" });


In this chapter, we have seen how wonderful the world of AI in video games is. We explored the history behind video games, both in Academia and in the industry. We have planned our journey in this book and explained what it will look like.

Now, it is time to prepare ourselves because, starting from the next chapter, we are going to get our hands dirty and jump straight into Unreal Engine.

About the Author

  • Francesco Sapio

    Francesco Sapio received his Master of Science in Engineering in Artificial Intelligence and Robotics degree from Sapienza University, Rome, Italy, a couple of semesters in advance, graduating with summa cum laude; he is currently a researcher at the same university.

    He is an Unreal and Unity 3D expert, skilled game designer, and an experienced user of major graphics programs. He helped the development of many games (both educational and commercial). He is also an active writer on the topic of game development.

    Finally, Francesco loves math, philosophy, logic, and puzzle solving, but most of all, creating video games—thanks to his passion for game designing and programming.

    Browse publications by this author

Latest Reviews

(2 reviews total)
There are many youtube clip for Unreal AI feature. But this book provide step by step guide that readers are able to catch the actual workflow based on theoritical background. Text is also friendly and digest to read.
too much superficial theory and too little practice

Recommended For You

Book Title
Access this book, plus 8,000 other titles for FREE
Access now