Unreal Engine 4 Tutorial: Artificial Intelligence

In this Unreal Engine 4 tutorial, you will learn how to use behavior trees and AI Perception to create a simple AI character that roams and attacks enemies. By Tommy Tran.

4.8 (29) · 1 Review

Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Using Observer Aborts

Observer aborts will abort a subtree if the selected blackboard key has changed. There are two types of aborts:

  1. Self: This setting will allow the attack subtree to abort itself when Enemy becomes invalid. This can occur if the Enemy dies before the attack subtree completes.
  2. Lower Priority: This setting will cause lower priority trees to abort when Enemy is set. Since the roam subtree is after attack, it is of lower priority.

Set Observer Aborts to Both. This will enable both abort types.

Unreal Engine 4 AI Tutorial

Now, the attack subtree can immediately go into roaming if it no longer has an enemy. Also, the roam subtree can immediately go into attack mode once it detects an enemy.

Here is the complete behavior tree:

Unreal Engine 4 AI Tutorial

Summary of attack subtree:

  1. Selector will run the attack subtree if Enemy is set
  2. If it is set, the Pawn will move and rotate towards the enemy
  3. Afterwards, it will perform an attack
  4. Finally, the Pawn will wait two seconds

Summary of roam subtree:

  1. Selector will run the roam subtree if the attack subtree fails. In this case, it will fail if Enemy is not set.
  2. BTService_SetRandomLocation will generate a random location
  3. The Pawn will move to the generated location
  4. Afterwards, it will wait for five seconds

Close BT_Muffin and then press Play. Spawn some muffins and prepare for the deadliest battle royale ever!

Unreal Engine 4 AI Tutorial

Where to Go From Here?

You can download the completed project here.

As you can see, it’s easy to create a simple AI character. If you want to create more advanced AI, check out the Environment Query System. This system will allow your AI to collect data about the environment and react to it.

If you want to keep learning, check out the next post in the series, where I’ll show you how to create a simple first-person shooter.

Tommy Tran

Contributors

Tommy Tran

Author

Over 300 content creators. Join our team.