Hands-On Artificial Intelligence with Unreal Engine - Francesco Sapio - E-Book

Hands-On Artificial Intelligence with Unreal Engine E-Book

Francesco Sapio

0,0
36,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Learn to build intelligent and responsive Non-Player Characters for your games with Unreal Engine Game AI.




Key Features



  • Understand the built-in AI systems in Unreal Engine for building intelligent games


  • Leverage the power of Unreal Engine 4 programming to create game AI that focuses on motion, animation, and tactics


  • Learn to profile, visualize, and debug your Game AI for checking logic and optimizing performance





Book Description



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.





What you will learn



  • Get an in-depth knowledge about all the AI Systems within Unreal Engine


  • Create complex AIs, understanding the art of designing and developing Behavior Tree


  • Learn how to perform Environmental Queries (EQS)


  • Master the Navigation, Perception, and Crowd Systems


  • Profile and Visualize the AI Systems with powerful debugging tools


  • Extend every AI and Debug system with custom nodes and functions





Who this book is for



Hands-On Artificial Intelligence with Unreal Engine is for you if you are a game developer with a bit experience in Unreal Engine, and now want to understand and implement believable game AI within Unreal Engine. The book will be both in Blueprint and C++, allowing people from every background to enjoy the book. Whether you're looking to build your first game or expand your knowledge to the edge as a Game AI Programmer, you will find plenty of exciting information and examples of game AI in terms of concepts and implementation, including how to extend some of these systems.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 440

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Hands-On Artificial Intelligence with Unreal Engine

 

 

 

 

 

Everything you want to know about Game AI using Blueprints or C++

 

 

 

 

 

 

 

Francesco Sapio

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Hands-On Artificial Intelligence with Unreal Engine

Copyright © 2019 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Acquisition Editor:Larissa PintoContent Development Editor:Akhil NairTechnical Editor: Ralph RosarioCopy Editor: Safis EditingProject Coordinator:Kinjal BariProofreader: Safis EditingIndexer:Manju ArasanGraphics:Alishon MendonsaProduction Coordinator: Jisha Chirayil

First published: April 2019

Production reference: 1240419

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN 978-1-78883-565-7

www.packtpub.com

 

To all of the game developers out there who are bold enough to travel and create magical worlds and dedicate their life and soul for the joy of others.

– Francesco Sapio
 
mapt.io

Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

Why subscribe?

Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

Improve your learning with Skill Plans built especially for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

Contributors

About the author

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.

I'm thankful to my love for her infinite patience, enthusiasm, and support. I do love you. Moreover, I'm thankful to the rest of my family, in particular to my parents and grandparents for their constant encouragement to do better in my life with the Latin expressions "Ad maiora" and "Per aspera ad astra". Finally, a huge thanks to all the special people around me whom I love, but that this acknowledgment is too short to properly mention them.

About the reviewers

Lauren S. Ferro has a Ph.D. in player profiling and modeling. She is currently an Adjunct Professor and researcher at Sapienza University, in Rome. Lauren is also the co-organizer of the Unreal Engine Meetup in Rome. In addition, she created the game design resource Gamicards, which is a prototyping tool for game experiences. At heart, she is intrigued by how we interact with the world and those in it.

Packt Publishing – For the opportunity to review this book.  Francesco Sapio – for providing a great contribution to the world of artificial intelligence and game development with this book.  My family – for their motivation, patience, support, and encouragement in everything that I do.

Katax Emperor is originally from Melbourne, Australia. He received bachelor's degree in Computer Hardware Engineering and two master's degree in Multimedia at Swinburne University of Technology in 2012.

Katax is involved in particle system programming, developing web-based interactive applications such as games, making animation with 3D applications for use in Unreal Engine, and also doing VJ performance with real-time improvisation style. Katax started programming with Commodore 64 and started making digital art works with Commodore Amiga 500. After Windows 98 was released, he switched to PC. He expanded his experience with 3D applications, fractal and graphic design, and video editing programs. Today, he has a wide range of experience in a number of applications for artists, designers, and developers.

I am grateful to John Carmack from id Software for his great work on 3D graphic programming. What he developed in the 90's was the beginning of the wonderful genre of first-person shooter games. Also, I would like to thank Westwood Studios for introducing the Command and Conquer (C&C) series. This game pioneered many aspects of the modern real-time strategy games, which later powered many sub-genres in this area as well.

Packt is searching for authors like you

If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

Table of Contents

Title Page

Copyright and Credits

Hands-On Artificial Intelligence with Unreal Engine

Dedication

About Packt

Why subscribe?

Packt.com

Contributors

About the author

About the reviewers

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Conventions used

Get in touch

Reviews

Section 1: The Unreal Framework

Making the First Steps in the World of AI

Before starting...

Prerequisites

Installing and preparing the software

Unreal Engine

Visual Studio

Becoming an AI Game Developer

What it means to be an AI Game Developer

AI in the game development process

A bit of history

What is AI?

A glance into the past

AI in games

AI in games – Industry and Academia

Planning our journey

Technical terminology

The bottom-up approach

The agent schema

Unreal Engine AI Framework

A sketch of our journey

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

Navigation (chapters 3 and 7)

Environment Query System (chapters 4 and 12)

Agent Awareness (chapters 5 and 12)

Crowds (chapter 7)

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

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

Going beyond (chapter 14)

Enabling AI for C++ users

Summary

Behavior Trees and Blackboards

How Behavior Trees work

The structure of a Mathematical Tree

Behavior Tree components

Root

Tasks

Composite

Decorators

Service

Blackboards and their integration with Behavior Trees

Creating our AI project

Starting Behavior Trees from AI Controllers

Creating the Behavior Tree and the Blackboard 

Creating the Blackboard

Creating the Behavior Tree

The AI Controller to run a Behavior Tree

AI Controller in Blueprint

AI Controller in C++

Summary

Navigation

What to expect from a Navigation System

Unreal Navigation System

Generating the Navigation Mesh

Setting parameters for the Nav Mesh

Display settings

Generation settings

Project Settings

Settings on the Character Movement Component

Modifying the Navigation Mesh

Nav Modifier Volume

Nav Mesh Areas

Creating a NavArea class in Blueprint

Creating a NavArea class in C++

Nav Link Proxy

Creating a Nav Link Proxy

Simple Links and Smart Links

Both Simple and Smart Links

Simple Links

Smart Links

Other settings of the Nav Link Proxy

Extending the Nav Link Proxy

Navigation Avoidance

Navigation Filtering

Creating a Navigation Filter in Blueprint

Creating a Navigation Filter in C++

Overriding the Navigation System

Summary

Environment Querying System

Enabling the Environment Querying System

Understanding the Environment Querying System

The general mechanism of EQS

The components of an Environment Query

Environment Queries

Contexts

Generators

Tests

Visual representation of the components

Running an Environmental Query within a Behavior Tree

Not only Locations, but also Actors!

Exploring the built-in nodes

Built-in Contexts

Built-in Generators

Actors Of Class

Current Location

Composite

Points: Circle

Points: Cone

Points: Donut

Points: Grid

Points: Pathing Grid

Built-in Tests

Visualizing Environment Queries

Creating components for the Environment Querying System

Creating Contexts

Creating the Player Context in Blueprint

Creating the Player Context in C++

Creating Generators

Creating Tests

Summary

Agent Awareness

Perception of AI in video games

Sound

Footsteps

Knocking over objects

Position

Zone of proximity

Interacting with other enemies

It isn't all about the "enemy"

Perceptive AI isn't just humanoid or animalistic

Impact of Players

Overview of the Sensing System

The AIPerceptionComponent

AIPerceptionComponent in Blueprint

Sense – Sight

Sense – Hearing

AIPerceptionComponent and Senses in C++

Different Teams

The AIStimuliSourceComponent

All Pawns are automatically detected

AIStimuliSourceComponent in Blueprint

AIStimuliSourceComponent in C++

Hands-on with the perception system – Sight AI Controller

A Blueprint perception system

A C++ perception system

Testing it all

Summary

Extending Behavior Trees

A quick recap on Behavior Trees

Creating a Task

Creating a Blueprint Task

Creating a Task in C++

Creating a Decorator

Creating a Decorator in Blueprint

Creating a Decorator in C++

Creating a Service

Creating a Service in Blueprint

Creating a Service in C++

Creating a Composite Node

Creating new type of nodes or new types of Trees

Summary

Crowds

Crowds in games

Building believable crowds

Animals

Crowd movement

Crowd dynamics and creating realistic behavior

Flow-based

Entity-based

Agent-based

Crowds in Unreal

Reciprocal Velocity Obstacles (RVO)

RVO in Unreal

Advanced RVO settings

RVO in Blueprint

RVO in C++

RVO observations

RVO resources

Detour Crowd

How the Detour Crowd system works

Using the Detour Crowd system

Detour Crowd settings

Debugging the Detour Crowd Manager

More crowd resources

Summary

Section 2: Designing and Implementing Behavior Trees

Designing Behavior Trees - Part I

The Expected Behavior

Building the Nodes

Nodes that already exist

Decorator – check variable

Check Variable Blueprint implementation

Check Variable C++ implementation

Task – Find Random Location

Find Random Location Blueprint implementation

Find Random Location C++ implementation

AI Controller

Implementing the AI Controller in Blueprint

Implementing the AI Controller in C++

Using the AI Controller

Summary

Designing Behavior Trees - Part II

Setting up the environment for testing the Behavior Tree

Creating the Player

Creating the Chasing Agent

Preparing the Level

Service – Update Chasing Behavior

Update Chasing Behavior Blueprint implementation

Update Chasing Behavior C++ implementation

Summary

Designing Behavior Trees - Part III

Building the Behavior Tree

Setting up the Blackboard

Building the Tree

Running the Behavior Tree

Running the Behavior Tree using the Blueprint controller

Running the Behavior Tree using the C++ controller

Bug Correction

Improving further (C++ only)

Node Name

A better description for the Decorator

Filtering Blackboard Keys

Summary

Section 3: Debugging Methods

Debugging Methods for AI - Logging

Basic Logging

Console Logging and on-screen messages in Blueprint

On-screen messages in C++

Console Logging in C++

Creating a Custom Logging Category (C++)

Summary

Debugging Methods for AI - Navigation, EQS, and Profiling

Debugging behavior trees

Profiling and visualizing environmental queries

Visualizing environmental queries with the EQS testing pawn

Creating the EQS testing pawn

Creating a test environmental query

Settings of the EQS testing pawn to visualize environmental queries

Profiling environmental queries

Setting up the test assets for EQS profiling

The environmental query profiler

Saving and loading EQS stats

Testing and visualizing the navigation mesh

Visualizing the navigation mesh

Navigation test actor

Profiling AI

Profiling with the console

Creating a custom stat group

Session frontend

Summary

Debugging Methods for AI - The Gameplay Debugger

The anatomy of the Gameplay Debugger

Gameplay Debugger Extensions

Gameplay Debugger categories

Category 0 – Navmesh

Category 1 – AI

Category 2 – Behavior Tree

Category 3 – EQS

Category 4 – Perception

The Nav Grid Category

Multiple Categories on-screen

More Categories

Gameplay Debugger settings

Extending the Gameplay Debugger

Creating a module with the use of a new plugin

Setting up the module to work with the Gameplay Debugger

Creating a new Gameplay Debugger Category

Registering the Gameplay Debugger Category

Visualizing the custom Gameplay Debugger Category

Creating an Extension for the Gameplay Debugger

The structure of the Extension

Creating the Extension class

Registering the Extension

Summary

Going Beyond

Why is psychology an important consideration for AI?

Psychology and AI in games

Building better AI through psychology

Machine learning

Uses of AI and machine learning in games

Uses for AI in games

Uses for machine learning in games

Adaptive behavior

What we haven't covered in this book

Motion and navigation (low level)

Racing games

Agent awareness

Environment Query System

Decision-making and planning

Discrete games/board games

Learning techniques

Procedural Content Generation (PCG)

Search and optimization

Multi-Agent Systems

AI and psychology

Going beyond classical AI

Much, much, much more!

Some useful resources

AI and philosophy

Goodbye

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

Learning how to apply AI is crucial and can take the fun factor to the next level when developing traditional, educational, or any other kind of game. Unreal Engine is a powerful game development engine that allows you to create 2D and 3D games. 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 with breaking down artificial intelligence (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 how to work through the built-in AI framework to build believable characters for every genre (e.g. RPG, Strategic, Platform, FPS, Simulation, Arcade, and Educational games). You will learn how to configure Navigation, Environmental Querying and Sensory systems for your AI agents and couple it with Behavior Trees, all with practical examples. You will then explore how the engine handles dynamic crowd. 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.

Who this book is for

This book is for you if you are a game developer with a bit experience in Unreal Engine, and now want to understand and implement believable game AI within Unreal Engine. The book will be both in Blueprint and C++, allowing people from every background to enjoy the book. Whether you're looking to build your first game or to expand your knowledge as a Game AI Programmer, you will find plenty of exciting information and examples of game AI in terms of concepts and implementation, including how to extend some of these systems.

What this book covers

Chapter 1, Moving the First Steps in The AI World, explores the prerequisites to becoming an AI game developer and how AI is used in the game development pipeline.

Chapter 2, Behavior Trees and Blackboards, introduces you to two principal structures used within the Unreal AI framework, which are used to control most AI agents in games. You will learn how to create a Behavior Tree and how these can store data within Blackboards.

Chapter 3, Navigation, teaches you how an agent can navigate or find a path through a map or the environment.

Chapter 4, Environment Query System, helps you get to grips with making an Environmental Query, which is a subsystem of the Unreal AI Framework for spatial reasoning. Mastering them is key in implementing believable behaviors within Unreal. 

Chapter 5, Agent Awareness, deals with how an AI agent can sense the world and the surrounding environment. These include sight, sound, and potentially any sense you might imagine (by extending the system). 

Chapter 6, Extending Behavior Trees, takes you through the task of extending behavior trees with Unreal by using Blueprint or C++. You will learn how to program new Tasks, Decorators, and Services.

Chapter 7, Crowds, explains how to handle crowds within the Unreal AI Framework that offer some functionality.

Chapter 8, Designing Behavior Trees – PartI, focuses on how to implement a Behavior Tree so that the AI agent can chase our player in the game (both in Blueprint and C++). This chapter, along with the next two, explores this example from designing to implementation.

Chapter 9, Designing Behavior Trees – Part II, is a continuation of the previous chapter. In particular, we will build the last missing piece of the puzzle (a custom Service) before we build our final Behavior Tree in the next chapter.

Chapter 10, Designing Behavior Trees – Part III, is a continuation of the previous chapter and is the final part of Designing Behavior Trees. We will finish what we started. In particular, we will build the final Behavior Tree and make it run.

Chapter 11, Debugging Methods for AI – Logging, examines a series of methods that we can use to debug our AI systems, including console logging, on-screen messages in Blueprint, and many more. By mastering the art of logging, you will be able to easily keep track of your values and which part of the code you are executing.

Chapter 12, Debugging Methods for AI – Navigation, EQS, and Profiling, exploresa number of more specific tools for the AI systems that are incorporated within Unreal Engine. We will see some more tools for analyzing performance related to AI code, as well as tools to visualize Environmental Queries and the Navigation Mesh.

Chapter 13, Debugging Methods for AI – the Gameplay Debugger, gets you to explore the most powerful debugging tool and the best friend of any Unreal AI developer—Gameplay Debugger. This chapter will take you even a step further, by teaching how to extend this tool so to customize it to your needs.

Chapter 14, Going Beyond, concludes with some suggestions on how to explore the concepts presented (and others) beyond this book and some thoughts regarding AI.

To get the most out of this book

Being comfortable with using Unreal Engine 4 is an important starting point. The objective of this book is to take those who work with the technology to a level where they are comfortable enough with all aspects to be a leader and driver of that technology on a project. 

Download the example code files

You can download the code bundle for this book from here: https://github.com/PacktPublishing/Hands-On-Artificial-Intelligence-with-Unreal-Engine.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788835657_ColorImages.pdf.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Section 1: The Unreal Framework

In this section, we are going to explore in depth the built-in Unreal AI Framework. We will start from what are Behavior Trees and Blackboard, and we will proceed in learning about the Navigation System, the Environmental Querying System and the Perception System.  Towards the end of this section, we will also understand how Unreal handles large Crowds, and how we can extend (both in Blueprint and C++) our Behavior Trees, by creating custom Tasks, Decorators and Services.

The following chapters will be covered in this section:

Chapter 1

, Moving the First Steps in the AI World

Chapter 2

, Behavior Trees and Blackboards

Chapter 3

, Navigation

Chapter 4

, Environment Querying System

Chapter 5

, Agent Awareness

Chapter 6

Extending Behavior Trees

Chapter 7

Crowds

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.

Prerequisites

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

, G

oing 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 from Metal 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
and
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.