> For the complete documentation index, see [llms.txt](https://labgames-studio.gitbook.io/basic-enemy-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://labgames-studio.gitbook.io/basic-enemy-ai/documentation/enemy-ai/behaviours.md).

# Behaviours

***

## Overview

Enemy behaviours are defined through a [Behaviour Tree](https://dev.epicgames.com/documentation/en-us/unreal-engine/behavior-trees-in-unreal-engine) that controls how the AI transitions between different 'states' such as **Idle**, **Alerted** and **Target Interaction**. <mark style="background-color:green;">The behaviour tree acts as the decision-making backbone</mark>, combining modular tasks into fluid and reactive enemy behaviour.

Each behaviour is built as a *reusable subtree* that can be plugged into the main tree, making it easy to extend or customise for new enemy types. By combining these trees, developers can create enemies with varied personalities and strategies without rewriting core logic.

***

## Behaviour Tree Assets

Behaviour trees form the core of all AI decision-making processes within the Enemy AI - Toolkit. At the highest level is the `BT_Enemy` behaviour tree graph. This contains different subgraphs, each representing a different 'state': <mark style="background-color:green;">Target Interaction, Alerted and Idle</mark>. Each of these states is represented by a separate behaviour tree graph. While the main `BT_Enemy` graph decides which state to execute based on the current world state, as represented by the blackboard, the nested behaviours handle the active decision-making. The following table explains all behaviour tree graphs:<br>

<table><thead><tr><th>Name</th><th>Type<select><option value="dzqAShTGfEXQ" label="Main" color="blue"></option><option value="BGWi86GSjZnR" label="Nested" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>BT Enemy</td><td><span data-option="dzqAShTGfEXQ">Main</span></td><td>Handles the highest level of decision-making. Decides which general state to execute.</td></tr><tr><td>BT Target</td><td><span data-option="BGWi86GSjZnR">Nested</span></td><td>Handles concrete target interaction, such as movement towards the target and interaction with the combat system.</td></tr><tr><td>BT Alerted</td><td><span data-option="BGWi86GSjZnR">Nested</span></td><td>Handles investigation logic. It is triggered when the AI loses a target. It lets the AI investigate the last known target area.</td></tr><tr><td>BT Idle</td><td><span data-option="BGWi86GSjZnR">Nested</span></td><td>It handles the idle decision-making process. It is executed when there is no target and nothing to investigate. It handles waiting, roaming or patrolling based on the selected enemy's idle mode.</td></tr></tbody></table>

***

## Blackboard - World State

<mark style="background-color:green;">All enemy behaviour is based on decision-making through behaviour tree graphs.</mark> However, behaviour trees base their decision-making on the current world state, which is represented by the [Blackboard](https://dev.epicgames.com/community/learning/tutorials/Mldp/introduction-to-blackboard-and-behavior-trees). A blackboard essentially acts as a data container. Generally, there is one for each instance of your enemy agent. The AI <mark style="background-color:green;">controller writes data into the blackboard</mark> while the behaviour <mark style="background-color:green;">trees read data from it</mark> in order to make decisions. The following table provides a brief overview of all the data listed in the blackboard:

{% tabs %}
{% tab title="General" %}
Contains general data that is used troughout the entire behaviour tree collection. Used to manage high level info or often used data.

| Name            | Description                                                                                                                       |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Self Actor      | References the actor of the agent. Default in any blackboard.                                                                     |
| Origin Location | Holds the origin location. Selected by the AI controller, when the enemy is started. Takes agents postion at moment of execution. |
| Target          | Defines the actor currently selected as the enmies target.                                                                        |
| Idle Mode       | Defines what mode the enemy should try to execute while within idle state.                                                        |
| Alerted         | Defines if the enemy is currently alerted. Example: No target but still needs to investigate environment.                         |
| {% endtab %}    |                                                                                                                                   |

{% tab title="Roaming" %}
Contains data used to fine-tune the enemies roaming behaviour on a per instance level. Holds lots of values set in the config, written into the blackboard by the AI Controller.

| Name                | Description                                                                                                         |
| ------------------- | ------------------------------------------------------------------------------------------------------------------- |
| Roaming Location    | Holds the location where the agent should move while roaming. Set by environment queries in each roaming iteration. |
| Roam Wait Time      | Defines how long the agent should wait between each roaming iteration.                                              |
| Min. Roaming Radius | Describes the minimum distance (from agent to new location). Used by EQS to gather next roaming location.           |
| Max. Roaming Radius | Describes the maximum distance (from agent to new location). Used by EQS to gather next roaming location.           |
| {% endtab %}        |                                                                                                                     |

{% tab title="Patrolling" %}
Contains data used to fine-tune the enemies patrolling behaviour on a per instance level. Holds lots of values set in the config, written into the blackboard by the AI Controller.

<table><thead><tr><th width="349">Name</th><th>Description</th></tr></thead><tbody><tr><td>Route</td><td>The patrol route that the enemy should patrol along. Used to gather patrol points &#x26; locations. </td></tr><tr><td>Point Index</td><td>The current index representing the point along the patrol route. </td></tr><tr><td>Point Location</td><td>The location of the patrol point in world space. Used as the agents movement location.</td></tr><tr><td>Skip Point</td><td>If the next point should be skipped. Can happen randomly by a chance set in the enemy config. </td></tr><tr><td>Patrol Waiting Time</td><td>The waiting time at each (not skipped) patrol point in seconds.</td></tr></tbody></table>
{% endtab %}

{% tab title="Investigation" %}
Contains data used to support the investigation of areas while the AI is within alterted state. Holds lots of values set in the config, written into the blackboard by the AI Controller.

<table><thead><tr><th width="349">Name</th><th>Description</th></tr></thead><tbody><tr><td>Investigation Center</td><td>Defines the center of the area to investigate. For example the last known position of a lost target.</td></tr><tr><td>Investigation Iterations</td><td>Defines how many iterations of random investigation locations should be generated.</td></tr><tr><td>Investigation Min. Radius</td><td>Describes the minimum distance (from agent to new location). Used by EQS to gather next roaming location.</td></tr><tr><td>Investigation Max. Radius</td><td>Describes the maximal distance (from agent to new location). Used by EQS to gather next roaming location.</td></tr><tr><td>Investigation Waiting Time</td><td>Defines how long the agent should wait between each investigation iteration.</td></tr><tr><td>Investigation Iteration Location</td><td>Holds the new investigation location for the agent to move to.</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

***

## Nodes

The **Enemy AI - Toolkit** comes with several <mark style="background-color:green;">custom behaviour graph nodes</mark>. These nodes are used to deploy custom behaviour tailored to this system's exact use cases directly into the behaviour tree graph. The table below provides a quick overview of all the newly added nodes:

<table><thead><tr><th>Name</th><th>Type<select><option value="s1s2akF2uig0" label="Task" color="blue"></option><option value="ZZ8ulk4PrJg5" label="Service" color="blue"></option><option value="QdOCIyPe7NHg" label="Decorator" color="blue"></option></select></th><th>Description</th></tr></thead><tbody><tr><td>Get Patrol Point</td><td><span data-option="s1s2akF2uig0">Task</span></td><td>This allows you to reach the next patrol point along the selected patrol route.</td></tr><tr><td>Perform Attack</td><td><span data-option="s1s2akF2uig0">Task</span></td><td>Performs a weighted attack, based from all attacks set in the enemy config. </td></tr><tr><td>Set Bool</td><td><span data-option="ZZ8ulk4PrJg5">Service</span></td><td>Sets a bool within the world state. Can be attached to other nodes in the behaviour tree graph. </td></tr><tr><td>Mode Comparer</td><td><span data-option="QdOCIyPe7NHg">Decorator</span></td><td>Compares the currently active mode with a custom value.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://labgames-studio.gitbook.io/basic-enemy-ai/documentation/enemy-ai/behaviours.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
