Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Unreal Engine 4 AI Programming Essentials
Unreal Engine 4 AI Programming Essentials

Unreal Engine 4 AI Programming Essentials: Create responsive and intelligent game AI using Blueprints in Unreal Engine 4

eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Unreal Engine 4 AI Programming Essentials

Chapter 2. Creating Basic AI

In this chapter, we will create our first AI step-by-step and talk about the techniques that we demonstrate along the way. So today, we will dive right into Unreal Engine 4 using the bare components needed to create a single state with random movement for your AI. We will then review what we've done, the changes we can make, and the disadvantages of the techniques demonstrated.

This chapter will cover:

  • Setting up our project
  • Creating the AIController
  • Sending instructions to Pawn with the AIController
  • Creating small blueprint scripts to assist in navigation

Goal

Our goal for this chapter is to place an AI character in the level that has the blueprint to instruct it to move randomly and indefinitely. We will demonstrate multiple techniques throughout this chapter to get a good grasp of some really basic AI techniques commonly featured in titles. These techniques are listed as follows:

  • First, we want to place an AI character, Hero, in the level that has the blueprint to instruct it to move randomly and indefinitely. We will achieve this by first creating a new third-person project and naming it appropriately. We will then use the default pawn provided from the sample content as the bot. We will create an AIController to control our pawn. We will then provide our AIController with instructions to move our bot randomly and indefinitely.
  • Second, we want to make the AI character follow some basic path. For example, we'll have the AI move along the walls in one direction. We can take our existing project and modify the AIController with new instructions...

Setting up the project

Let's open up Unreal Engine 4! We will begin with the first process of creating a new project.

Note

We will use Unreal Engine 4.6.0 throughout this book. The instructions may vary per version. We will present the idea behind our actions as we demonstrate them using Unreal Engine 4; so, hopefully, you will be able to translate the instructions as you see fit.

Here, we will use the Third Person Shooter template, which allows us to easily observe how the character moves in the environment. Perform the following steps:

  1. Go to the New Project window if you aren't there already:
    Setting up the project
  2. Select the Third Person blueprint project:
    Setting up the project
  3. Name your project as you see fit; I've named mine ImprovedAI. Then, hit Create Project in the lower-right corner of the window.

Environment

Even though we are using the Third Person blueprint template, these techniques can be used on other templates as well. You must adapt what you learn here. That being said, what you start to understand is that...

Using our new AIController class

Ever notice how one player can be any character they desire? This is the hierarchy that creates the pawn and the controller. The controller is what the player inherits after waiting for some time in the game lobby. It is used to manage the input and connection from the player. This class comes with additional functions to help navigate the bot and the ability to assign a Behavior Tree to the controller. In this demonstration, we will cover some of the basics of the AIController class.

Assigning the AIController class

So, now that we have what we need to create an AI, we will assign the MyController class to the MyCharacter base. To do so, go to the Defaults section within the MyCharacter blueprint. Search for AIController Class and set it to MyController, as shown in the following screenshot:

Assigning the AIController class

When a character isn't possessed, it will automatically be possessed by AIController. So, with the change we just made, the default AIController class that possesses...

Reviewing the current progress

You can wipe the sweat from your forehead; the hard work has yet to begin. So, what have we done so far?

  • We've set up our AI project
  • We've set up our pawn with our new AIController
  • We've sent instructions to our pawn using AIController

We're halfway there. This simple setup allows us to put all our instructions on our AIController, which will possess the pawn we created from the sample content. The AIController is assigned to pawns, which means that multiple pawns can share the same AIController.

As we can see, our AI now runs indefinitely. Perfect! Let's move on to the second section of this chapter!

Adding the challenge

Now, we will add line traces to the AI character. In our demonstration, we will use traces to detect the wall in front of the pawn. Other examples of using traces in the AI include Line of Sight checking, getting surface rotation, and getting nearby actors.

Let's go back to Unreal Engine Level Editor and look within Content Browser. Perform the following steps:

  1. Rename our MyController blueprint Hero; this will act as the player in this scenario.
  2. Open our Hero blueprint and go to the EventGraph section.
  3. Now, remove every node except the Event Tick and Move to Location nodes. We will replace these with new blueprint scripting:
    Adding the challenge

    Blueprint after removing unnecessary nodes

  4. Pull from the return exec pin on the Event Tick node and create a Delay node.
  5. Set the Duration value to .05 so that it will update relatively fast.
  6. Now, we have to get the location from the pawn to create line traces. We will also use the right vector to face the pawn to the right from the pawn's current...

Goal


Our goal for this chapter is to place an AI character in the level that has the blueprint to instruct it to move randomly and indefinitely. We will demonstrate multiple techniques throughout this chapter to get a good grasp of some really basic AI techniques commonly featured in titles. These techniques are listed as follows:

  • First, we want to place an AI character, Hero, in the level that has the blueprint to instruct it to move randomly and indefinitely. We will achieve this by first creating a new third-person project and naming it appropriately. We will then use the default pawn provided from the sample content as the bot. We will create an AIController to control our pawn. We will then provide our AIController with instructions to move our bot randomly and indefinitely.

  • Second, we want to make the AI character follow some basic path. For example, we'll have the AI move along the walls in one direction. We can take our existing project and modify the AIController with new instructions...

Setting up the project


Let's open up Unreal Engine 4! We will begin with the first process of creating a new project.

Note

We will use Unreal Engine 4.6.0 throughout this book. The instructions may vary per version. We will present the idea behind our actions as we demonstrate them using Unreal Engine 4; so, hopefully, you will be able to translate the instructions as you see fit.

Here, we will use the Third Person Shooter template, which allows us to easily observe how the character moves in the environment. Perform the following steps:

  1. Go to the New Project window if you aren't there already:

  2. Select the Third Person blueprint project:

  3. Name your project as you see fit; I've named mine ImprovedAI. Then, hit Create Project in the lower-right corner of the window.

Environment

Even though we are using the Third Person blueprint template, these techniques can be used on other templates as well. You must adapt what you learn here. That being said, what you start to understand is that these techniques...

Using our new AIController class


Ever notice how one player can be any character they desire? This is the hierarchy that creates the pawn and the controller. The controller is what the player inherits after waiting for some time in the game lobby. It is used to manage the input and connection from the player. This class comes with additional functions to help navigate the bot and the ability to assign a Behavior Tree to the controller. In this demonstration, we will cover some of the basics of the AIController class.

Assigning the AIController class

So, now that we have what we need to create an AI, we will assign the MyController class to the MyCharacter base. To do so, go to the Defaults section within the MyCharacter blueprint. Search for AIController Class and set it to MyController, as shown in the following screenshot:

When a character isn't possessed, it will automatically be possessed by AIController. So, with the change we just made, the default AIController class that possesses our...

Reviewing the current progress


You can wipe the sweat from your forehead; the hard work has yet to begin. So, what have we done so far?

  • We've set up our AI project

  • We've set up our pawn with our new AIController

  • We've sent instructions to our pawn using AIController

We're halfway there. This simple setup allows us to put all our instructions on our AIController, which will possess the pawn we created from the sample content. The AIController is assigned to pawns, which means that multiple pawns can share the same AIController.

As we can see, our AI now runs indefinitely. Perfect! Let's move on to the second section of this chapter!

Left arrow icon Right arrow icon

Key benefits

  • Understand and apply your Game AI better through various projects such as adding randomness and probability, and introducing movement
  • Configure and debug Game AI logic using multiple methodologies
  • Bridge the gap between your knowledge and Game AI in Unreal Engine 4

Description

Unreal Engine is a powerful game development engine that provides rich functionalities to create 2D and 3D games. Developers have the opportunity to build cross-platform mobile and desktop games from scratch. This book will show you how to apply artificial intelligence (AI) techniques to your Unreal project using blueprints as your scripting language. You will start with an introduction to AI, and learn how it is applied to gaming. Then you'll jump right in and create a simple AI bot and apply basic behaviors to allow it to move randomly. As you progress, you'll find out how to implement randomness and probability traits. Using NavMesh, you will impart navigation components such as character movement, MoveTo nodes, settings, and world objects, and implement Behavior Trees. At the end of the book, you will troubleshoot any issues that might crop up while building the game.

Who is this book for?

This book is for programmers and artists who want to expand their knowledge of game AI in relation to Unreal Engine 4. You are recommended to have some experience of exploring Unreal Engine 4 prior to this book because we jump straight into game AI.

What you will learn

  • ? Understand the fundamental components of game AI within Unreal Engine 4
  • ? Skillfully introduce game AI within Unreal Engine 4
  • ? Configure, customize, and assign navigation and AI components to your pawn
  • ? Create, debug, and analyze game AI behavior
  • ? Design responsive game AI using the Behavior Tree methodology
  • ? Create smart objects designed to interact with AI
  • ? Utilize advanced AI features within your project to maximize the user experience

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 18, 2016
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393120
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Mar 18, 2016
Length: 188 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393120
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 107.97
Unreal Engine Game Development Blueprints
€41.99
3D Game Design with Unreal Engine 4 and Blender
€35.99
Unreal Engine 4 AI Programming Essentials
€29.99
Total 107.97 Stars icon

Table of Contents

10 Chapters
1. Introduction to Game AI Chevron down icon Chevron up icon
2. Creating Basic AI Chevron down icon Chevron up icon
3. Adding Randomness and Probability Chevron down icon Chevron up icon
4. Introducing Movement Chevron down icon Chevron up icon
5. Giving AI Choices Chevron down icon Chevron up icon
6. How Does Our AI Sense? Chevron down icon Chevron up icon
7. More Advanced Movement Chevron down icon Chevron up icon
8. Creating Patrol, Chase, and Attack AI Chevron down icon Chevron up icon
9. What Have We Learned? Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.6
(12 Ratings)
5 star 25%
4 star 16.7%
3 star 0%
2 star 8.3%
1 star 50%
Filter icon Filter
Top Reviews

Filter reviews by




Andrew McLennan-Murray Jul 22, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book gives a good introduction to the built in AI systems in UE4. Besides this book, Epic's documentation, and some user created docs, you'll be hard pressed to find more in one text. After going through the material I realized some of what I needed to do was not built in to UE. I reached out directly to the author. He was extremely knowledgeable and helpful in guiding me toward a solution and more resources.
Amazon Verified review Amazon
Peter Newton Apr 16, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If anyone has any issues with my product, email me@peterlnewton.com for any explanations or concerns. I will not be able to revise this copy of the book as this is now allowed by the publisher. When I first wrote this I just began as an instructor, so I apologies as the teaching quality is sub-par to what I capable of doing now. I have learned a lot since I first wrote this book over nearly 2 years ago.
Amazon Verified review Amazon
Hugo May 15, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Unreal engine is a powerful AAA cross platform game engine that enable you to develop high quality games, this book teach me how to use blueprints visual tool to build my game logic, this is amazing how much you can achieve, Unreal already have a great set of tools that provide common AI, this book explain some of them, enabling me to apply their in my game easily without any line of code, I like to code, but to implement AI only in code I would have to spend much more time and effort. The book starts from foundations of AI in game development, after that you will start from basic techniques, teaching how these features work, giving you the idea of where to use it and the possibilities that you achieve combining these features with other to create more complex interesting behaviors like movements, randomness, probabilities, behavior trees, sensors, path followings and others. This can make your game so much fun and immersive, your players will have a much better gaming experience and you be proud of your work. This book has a great structure and if you never worked with game AI programming in Unreal Engine you will feel comfortable as you read this because the author has explained almost from scratch all the concepts and techniques, I think this way you learn for sure and be able to extend what you know, the game AI is almost limitless.
Amazon Verified review Amazon
Fernando M. Jul 18, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good explanation of all AI background in blueprint domain. The book is synthetic and essential describes only one example for each argument,but effective.
Amazon Verified review Amazon
cookie Feb 16, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Saw some upset comment, thus understand their feelings. I decided to give a read given that I realize my BP was rusty understanding level, the author did display some good technique like for instance using the the FIND with the Give Access Node and Cast <3personChar>. I find this bewildering as there is no explanation but after spending 8hours of researching, begin to understand the logic behind it. It basically just to compare the CharArrray Get access variable to the Possess Pawn Cast <3PersonChar> and provide access to the waypoint actors for the "Approved" pawn.Another given example was class = class. If I was a beginner i probably wun understand this either. It basically to boolean if the class IS equal to the matched class actor.Hope that this will not discourage the author as it covers the basics of AI in technical way, and I appreciate the techniques they shared. Hopefully they can come up another Book on AI with better explanation.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.