Course contentsShow
← Unreal Engine Game Development
Lesson 462 of 8806. AI, Navigation, and Decision MakingFree lesson

Managing Perception Memory and Forgetting Mechanisms

Control how long an AI remembers a target after they disappear from sight to create realistic search behaviors.

In this lesson, you will learn how to configure the AISenseConfig_Sight properties to control how long an AI retains a memory of a target after losing line-of-sight.

The Logic of "Forgetting"

By default, when an AI loses sight of a target, the perception system immediately marks the stimulus as expired. To make your AI feel human—or "search" for a player who just ducked behind a crate—you must decouple the loss of vision from the loss of memory. This is handled through Lose Sight Radius and Auto Success Range properties in your AI Perception Component.

The most critical setting is LoseSightRadius. This defines the distance at which the AI stops "tracking" the target if they disappear. However, the true "forgetting" happens via the AutoSuccessRangeFromLastSeenLocation and the PersistUntilForced settings.

Configuring Persistence

When you configure your Vision sense, you can adjust these values directly in the AISenseConfig_Sight asset or in your AI Controller’s constructor:

// Inside your AI Controller's SetupPerceptionSystem
UAISenseConfig_Sight* SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("SightConfig"));
SightConfig->SightRadius = 2000.0f;
SightConfig->LoseSightRadius = 2500.0f; 
// Time in seconds the AI "remembers" the target after losing sight
SightConfig->DetectionByAffiliation.bDetectEnemies = true;

To implement a "forgetting" delay, you utilize the OnTargetPerceptionUpdated delegate. When a stimulus expires, the AI doesn't have to instantly clear the Blackboard target. By checking the bSuccessfullySensed boolean in the FActorPerceptionUpdateInfo struct, you can trigger a "Search" state in your Behavior Tree instead of an immediate "Idle" state.

By increasing the LoseSightRadius compared to the SightRadius, you create a buffer zone. Even if the player is technically obscured, the AI keeps them in their short-term memory, preventing the "flickering" effect where the AI constantly flips between combat and idle states while a player is moving behind cover.

Key Takeaway: Use the LoseSightRadius to create a visual buffer and implement a delayed transition in your Behavior Tree to allow the AI to "investigate" the last known position before fully forgetting the target.