Lesson 4 gave the player speed bands, noise, and an exposure hook. This lesson gives the guard senses that consume those signals so stealth either works or fails for understandable reasons.
You are still not shipping full combat. You are proving detection: sight cones, hearing radius, and a minimal alert state you can read in-game.

Lesson objective
By the end of this lesson you will have:
- One enemy pawn with an AI Controller and AI Perception configured for sight and hearing.
- Stimulus registration so the player's movement or custom noise events register as hearable, and line-of-sight checks respect your Lesson 3 cover layout.
- Blackboard (or Blueprint) variables storing last known stimulus location and a simple alert level enum you will consume in Lessons 6–7.
Step 1: Stand up a test guard in your greybox
- Duplicate Lesson 2 naming: place a guard Blueprint under
/Game/Characters/AI(for exampleBP_Guard_M01). - Use a Character parent so perception, capsule, and future nav share a familiar stack.
- Drop the guard into L_Mission01_Greybox at a patrol endpoint you already liked in Lesson 3.
- Assign AI Controller Class to a dedicated
BP_GuardAIController(even if it is empty today—Lesson 6 will grow it).
Rule: one capsule height that matches eye height assumptions for sight sockets. Document eye socket name if you use mesh sockets for traces.
Step 2: Add AI Perception to the controller or pawn (pick one pattern)
Unreal teams split this two ways; stay consistent:
| Pattern | When |
|---|---|
| Perception on pawn | Fast prototypes; guard Blueprint owns AIPerception. |
| Perception on AI Controller | Cleaner for multiple pawn swaps later. |
For this course slice, pawn-owned perception is fine if your whole team agrees.
- Add AI Perception Component.
- Add AI Sight sense: set sight radius, peripheral angle, lose sight radius, and auto success from last seen to taste.
- Add AI Hearing sense: set hearing range wide enough to feel Lesson 4 noise at sprint, tight enough that sneak has margin.
Tune against your greybox metrics, not default engine numbers.
Step 3: Teach sight who matters
- Ensure the player pawn's collision/visibility is on channels sight uses (defaults usually work—verify after crouch height changes).
- Confirm AI Sight affiliation / detect neutrals / detect enemies checkboxes match your team IDs if you set them (slice: often everyone neutral until you formalize teams).
- If players disappear when crouched, verify collision capsule shrink actually lowers mesh sight point or adjust sight trace to use a head socket.
Common mistake: sight traces from feet while art reads eyes—detection feels "broken" unfairly both ways.
Step 4: Make hearing consume player noise
Link to Lesson 4 noise emitters:
- If you broadcast custom noise with location and loudness, ensure the player's pawn or movement calls
Pawn.MakeNoise/Report Noise Eventwith loudness mapped fromNoiseIntensity(Blueprint node names vary slightly by version—use the built-in noise event path that AI Hearing listens to). - Sprint + loud footfalls should spike hearing reliably; sneak should sit under threshold unless you want hyper-hearing guards.
- Temporarily print perceived stimuli or use AI Debug visualization (
Show Debug For AIor perception-focused console toggles in your UE build) to confirm events arrive.
Step 5: Alert levels without behavior trees yet
You still need readable state on the guard:
- Create an enumeration
E_AlertLevel(Calm,Suspicious,Aware). - On AI Perception
On Target Perception Updated(or delegate equivalent):- If sight succeeds, set Aware and stash stimulus location.
- If hearing fires without sight, bump Suspicious and stash noise location.
- Decay Suspicious with a simple timer if you want "maybe I heard something" beats—optional but sells stealth readability.
Persist data on a Blackboard Component if you already attached one; otherwise use variables on the guard until Lesson 6 imports the behavior tree.
Step 6: Debug draw until it feels honest
- Enable perception debug draws for your guard and walk Lesson 1 beat paths.
- Stand in cover at Lesson 3 cover height: player should fail sight if metrics agree.
- Sprint behind a wall: guard should hear, not magically see through BSP.
- Crouch-walk in open light: if Lesson 4 exposure is high, decide whether sight chance or secondary checks amplify detection later—log design debt instead of coding combat now.
Mini challenge
- Place two guards with different sight radii (short interior vs long corridor).
- Record time-to-detection for sneak vs walk vs sprint on the same straight line.
- Write one sentence in your design doc: which band is "fair" for your mission fantasy.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Never detects player | Wrong affiliation / team | Fix perception detect flags |
| Sees through walls | Collision channels or thin BSP | Thicken blockout; verify trace channel |
| Hearing never fires | Noise not using report path | Align with MakeNoise / hearing listener |
| Instant 360 vision | Peripheral angle too wide | Narrow peripheral; tune peripheral gradient |
| Sees crouched always | Eye trace height | Lower sight source or fix crouch mesh |
Summary
- AI Perception turns your slice from choreography into systems.
- Sight + hearing must agree with Lesson 3 space and Lesson 4 signals.
- Alert enums + last known location are the contract Lessons 6–7 will animate.
Further reading
- AI Perception in Unreal Engine – senses, stimuli, and debugging.
- Unreal Engine guides – companion material on this site.
- Packaging issues later: UE 5.5 packaging help.
FAQ
Perception vs Pawn Sensing?
For new work, prefer AI Perception—richer configuration and better scaling for multiple senses.
Does this replace line traces I wrote in Lesson 4?
No. Exposure and perception can coexist; later lessons decide which authority wins per difficulty mode.
Multiplayer later?
Authority and replication move to server-owned AI. This vertical slice stays offline-first unless you already chose otherwise in Lesson 1.
When guards hear a reckless sprint and lose a careful sneak behind cover, continue to Lesson 6: Patrol Routes and Guard Schedules—behavior trees and blackboards that move guards through the greybox using the alert data you stored here. Bookmark this lesson once On Target Perception Updated fires deterministically in your test map.