# AI Behavior Manager

<div align="left"><figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FOXndO6hKeLj0uEuE8Vaf%2FActorComponent_64x.png?alt=media&#x26;token=b00844b2-cbc3-4f89-9f4b-d2c8e193007c" alt=""><figcaption></figcaption></figure></div>

The **AI Behavior Manager (AC\_AI\_BehaviorManager)** component is responsible for managing AI states (such as Idle, Patrolling, Random Roam, Investigating, Combat, etc.), ensuring smooth transitions between them. Additionally, the component allows for **fine-tuning** AI behavior through various **configurable parameters**.

It is added to the **Soulslike Enemy (B\_Soulslike\_Enemy)** class by default.

### **How It Works**

* **Behavior Tree Initialization**
  * On **Begin Play**, the component checks if the AI has a valid **Behavior Tree** assigned.
  * If a **Patrol Path** is present, the AI starts in a **Patrolling** state immediately.
  * Otherwise, it defaults to the **Idle** state.
* **State Management**
  * The component dynamically adjusts the AI's **state** based on environmental triggers (e.g., detecting the player, being attacked).
  * State changes are handled through the **SetState** method, ensuring smooth transitions between behaviors.
* **Fine-Tuning AI Behavior**
  * The following parameters allow for **custom AI tuning**:
    * **MaxChaseDistanceThreshold:** Maximum distance AI will chase a target before stopping.
    * **AttackDistanceThreshold:** The distance at which AI will initiate an attack.
    * **StrafeDistanceThreshold:** Controls how far the AI must be from its target for strafing.
    * **SpeedAdjustDistanceThreshold:** Adjusts AI movement speed based on distance to the target.
    * **MinimumStrafePointDistance:** The minimum distance for strafing logic.
    * **StrafeMethods:** Defines how AI will strafe (e.g., directional preferences).
* **Event Based Blackboard Updates**
  * The component is responsible for **adjusting Blackboard values** to ensure the AI’s **Behavior Tree** reacts correctly to its state.
* **Target & Patrol Tracking**
  * The **SetTarget()** function updates AI’s **current target** (e.g., player or other AI).
  * The **SetPatrolPath()** function assigns a patrol route.

### Example Usage

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FwKJI5clLO58X23Tmj1Hh%2Fimage.png?alt=media&#x26;token=6760f787-a986-4e5a-a189-d96438186dcf" alt=""><figcaption></figcaption></figure>
