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

Integrating Hearing Senses for Sound-Based Detection

Utilize the Report Noise Event function to trigger AI awareness when players perform actions that generate audible sound.

In this lesson, you will learn how to trigger AI awareness by programmatically reporting sound events that the AIPerceptionComponent can detect.

The Mechanism of Sound Detection

While Vision sensing relies on line-of-sight and UAIPerceptionComponent settings, Hearing relies on an "event-based" architecture. In Unreal Engine, your AI does not "listen" for audio files playing in the world; rather, it listens for ReportNoiseEvent calls. This function acts as a broadcast, placing an invisible, temporary sphere in the world at a specific location that informs nearby AI agents of an audible disturbance.

Implementing ReportNoiseEvent

To make an action (like footsteps, a dropped object, or a gunshot) detectable, you call MakeNoise or UAISystem::ReportNoiseEvent from your character or item logic.

The ReportNoiseEvent requires four critical pieces of information:

  1. NoiseMaker: The actor creating the sound (the player).
  2. Loudness: A float determining how far the sound travels.
  3. MaxRange: The distance limit of the noise.
  4. InvestigationLocation: Where the sound originated.

Here is a typical implementation inside a character’s "fire weapon" function:

// Inside the Player's weapon logic
if (APawn* MyPawn = GetOwnerPawn())
{
    float Loudness = 1.0f;
    float MaxRange = 1500.0f;
    FVector SoundLocation = MyPawn->GetActorLocation();

    // Broadcast the noise to the AI Perception System
    UAISystem::ReportNoiseEvent(GetWorld(), SoundLocation, Loudness, MyPawn, MaxRange);
}

AI Perception Configuration

For this to work, your AI agent must have an AIPerceptionComponent with a UAISenseConfig_Hearing object added. Ensure that DetectionByAffiliation is correctly checked for "Neutrals" or "Enemies" so the AI knows to react to the player. When the AI Perception component detects this noise event, it triggers the OnPerceptionUpdated delegate. You can then extract the location of the sound from the FROISenseAffiliation data and update a Blackboard Key, which your Behavior Tree can then use to command the AI to move to that location.

Key Takeaway: Sound detection is an event-based system where you manually broadcast noise locations using ReportNoiseEvent to trigger AI sensory responses, independent of actual audio playback.