Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AI Enemy System Documentation

This project implements an autonomous AI Enemy character using Unreal Engine 5's Behavior Tree, Blackboard, and AI Perception systems. The AI transitions dynamically between an idle or roaming patrol routine and an active chase behavior depending on its sensory state.


1. Behavior Tree Structure

The execution flow of the AI is driven by a root Selector node, which evaluates its child branches from left to right. Logic is split into two prioritized sequences based on player visibility:

Chase Sequence (Left Branch - High Priority)

  • Guard Condition: This branch is wrapped in a Blackboard-Based Condition Decorator that checks if the boolean key CanSeePlayer Is Set (True).
  • Flow Control: The Observer Aborts rule is set to Self. When CanSeePlayer becomes true, this branch takes immediate priority over itself to execute cleanly.
  • Execution Flow:
    • Move To: Pathfinds the AI directly to the actor reference stored in the TargetActor blackboard key.
    • Wait: Halts the AI for 0.5s upon reaching the player before looping the chase check.

Patrol Sequence (Right Branch - Low Priority)

  • Guard Condition: This branch is wrapped in a Blackboard-Based Condition Decorator that evaluates if the key CanSeePlayer Is Not Set (False).
  • Execution Flow: Runs continuously as long as the player remains undetected.
    • BTT_FindPatrolLocation (Custom Task): Samples the surrounding navigation mesh (NavMesh), picks a random valid destination coordinate relative to the AI's origin, and writes it to the PatrolLocation key.
    • Move To: Commands the character movement component to walk toward the coordinates stored in PatrolLocation.
    • Wait: Pauses the AI at its destination for 2.0s to simulate a natural investigative delay before looking for a new point.

2. Blackboard Keys & Purpose

The Blackboard asset (BB_Enemy) handles the volatile operational memory for the system. It tracks the following specific keys:

  • SelfActor (Object): Automatically references the AI character instance itself for self-context queries within tasks.
  • TargetActor (Object): Stores the direct actor reference of the player character once a successful vision scan occurs. This serves as the target destination for the Chase branch.
  • PatrolLocation (Vector): Stores the $X, Y, Z$ coordinates generated by the custom task, mapping the destination for the passive wandering routine.
  • AIState (Enum/Int): Reserved for advanced state tracking or transition debugging.
  • CanSeePlayer (Bool): Acts as the system’s primary conditional toggle. Turning this flag on or off controls the structural flow of the Behavior Tree decorators.

3. Perception Sense Triggers (AI Sense_Sight)

The AI's sensory input is handled through a localized AI Perception Component configured inside the AI Controller blueprint using visual raycasting.

  • Vision Envelope: The AI continuously scans an area defined by its forward vision angle and maximum sight radius.
  • Detection Filters: The Sight Config features explicit affiliation checkboxes (Detect Enemies, Detect Neutrals, Detect Friendlies) turned on so that the player blueprint class is detected properly by the component traces.
  • Trigger Mechanics (On Target Perception Updated):
    • On Sight: When the player enters the visibility cone, the perception system fires an update event with a Successfully Sensed status of True. The AI Controller instantly updates the CanSeePlayer boolean key to true and stores the player character reference inside the TargetActor key, triggering the high-priority Chase sequence.
    • On Lost Line-of-Sight: When the player ducks behind solid cover or exits the maximum range envelope, the event updates with a Successfully Sensed status of False. The AI Controller fires a cooldown delay loop. If the player stays out of sight, it clears the CanSeePlayer and TargetActor keys, forcing the tree back into the low-priority Patrol branch.

Project Demonstration Video

You can watch the fully working AI implementation and behavior state transitions here:
Watch the Demonstration Video on YouTube

About

Assignment of the AI programming course using Unreal Engine

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors