Enemy AI
High-level introduction to the enemy AI framework and its core building blocks. Learn how the enemy AI is structured and how its main systems interact to create advanced behaviours.
Overview
At its core, the enemy AI is designed around states and behaviour rules defined in a central configuration asset. The AI controller reads this configuration to determine whether an enemy starts in a patrolling, roaming or idle state. From there, a behaviour tree controls the transitions between tasks such as patrolling, chasing, roaming and attacking.
Attacks themselves are driven by the modular combat system: attacks are selected randomly from the enemy’s configuration based on their weight and cooldown, preventing spam. A notify state within the animation toggles hitboxes on and off to ensure that only the correct frames deal damage. The system is interface‑driven and comes with a behaviour‑tree task for attacking, allowing it to integrate seamlessly into the AI workflow.
Key Concepts
The enemy AI is built around a set of core systems that work together to provide intelligent and modular behaviour. At the center lies a custom AIController, which is responsible for launching the behaviour tree and coordinating communication between movement, perception, combat, and health components. It reads the assigned enemy configuration to determine the initial state and updates blackboard values whenever perception events occur.
The actual decision-making is handled by the behaviour tree, where tasks such as “Patrol”, “Roam”, “Chase”, and “Attack” are combined to form fluid state machines. Combat is seamlessly integrated through the Attack Behaviour Task. This task retrieves the combat component from the pawn, requests an attack based on the configured weights and cooldowns, and waits for the attack-finished event before returning control, ensuring that attacks are synchronised with the underlying animation and combat system.
To detect targets in the world, the AI makes use of perception through Unreal’s AI Perception component. It can sense players via sight, hearing, or custom senses. When a target is detected or lost, the controller updates the blackboard accordingly, causing the behaviour tree to transition between states — for example, from patrolling to chasing.
The Environment Query System (EQS) provides the AI with the ability to find dynamic positions in the level, such as random roaming spots or tactical cover locations. Behaviour-tree tasks can execute EQS queries to choose suitable destinations and move the pawn there. These queries can be customised on a per-enemy basis, allowing different enemy types to behave uniquely within the same framework.
Finally, all settings can be configured in a single config asset. This configuration is then added to the character blueprint of your enemy and, with the help of blueprint interfaces, propagated to all the relevant systems. As the entire AI is heavily data-driven, you can create as many configurations as you like and switch between them with just a few clicks.
Quick Start
Setting up an enemy is a straightforward process and can be done in just a few steps. Every enemy must first be assigned an Enemy Config asset. This configuration defines the default state of the AI — whether the enemy begins patrolling, roaming, or idling — and also references any attack configurations that should be available during combat. Failing to assign a configuration asset will result in undefined behaviour!
Once the configuration is in place, you can rely on the provided behaviour tree, which already includes tasks for patrolling, roaming, reacting to perception events, and executing attacks. The default tree can be duplicated and customised to introduce additional states or to adapt existing behaviours to your project’s needs.
To make sure your enemies interact with the world as intended, it is important to tune the perception component on each character. Parameters such as sight radius or field of view determine how far and how wide the AI can detect players and other relevant actors.
Finally, for roaming behaviour or more advanced tactical movement, you can create EQS queries within your project. These queries can be referenced directly from the behaviour tree and allow the AI to pick suitable destinations in the environment, ensuring more dynamic and varied movement patterns. The Enemy AI - Toolkit already comes with premade Environment Query System Solutions.
Next Steps
The overview above gives you a general idea of how the enemy AI is structured and how its main systems interact. To make full use of the toolkit, it is helpful to understand each part in more detail and see how they can be customised for your own project. The following sections break down the most important building blocks of the AI, explain their responsibilities, and show how they fit together inside the behaviour tree.
Last updated