Lesson 6 gave patrol loops that yield when perception spikes. This lesson answers the next player question: “What does the guard do for the next ten seconds after they care?” You will add investigate, search, and cooldown behavior with clear exit rules, and stub a combat gate that your Lesson 1 fantasy allows—without turning the slice into a full shooter.

Lesson objective
By the end of this lesson you will have:
- Blackboard-driven states beyond patrol: at minimum Investigate, Search, Engage (or Challenge), and Cooldown / Reset.
- A Behavior Tree priority stack where Engage beats Search, which beats Investigate, which beats Patrol.
- Timers or gameplay cues that force stand-down or escalation so guards do not infinite-loop on stale stimuli.
Step 1: Name the states honestly
Align names with what players see:
| State | Player-readable moment |
|---|---|
| Calm | Normal patrol from Lesson 6 |
| Suspicious | Heard something; head turns, shorter moves |
| Investigating | Moving toward StimulusLocation with caution |
| Searching | Lost direct line; sweeping an area or last-known bubble |
| Engaged | Confirmed threat: combat, alarm, or scripted flee (per Lesson 1) |
If your fantasy forbids guns in v1, Engaged can mean detain or alarm call—the tree structure stays the same.
Step 2: Blackboard keys to add
Extend BB_Guard (or equivalent):
SearchPhaseTimer(float) – how long to sweep before giving up.LastStateChangeTime(float) orTimeSinceLastSight– decay and fairness.bLineOfSight(bool) – updated by perception or a cheap LOS check to avoid flapping.CombatAllowed(bool) – off by default until you prove AI in a ring; matches Lesson 1 scope.
Pro tip: keep one writer for AlertLevel—perception delegates suggestions, the tree commits transitions to reduce race bugs.
Step 3: Suspicion and investigate
- On hearing without sight: set Suspicious, copy stimulus to a move target slightly offset (guards should not stand inside walls).
- Move To with slow speed and acceptance radius tuned for “peek corners,” not marathon sprints.
- If sight confirms while investigating, jump to Engaged (or your non-lethal equivalent).
Step 4: Search windows and cooldown
When LOS breaks after being Aware:
- Enter Search: pick N sample points around LastKnownLocation (simple grid or randomized offsets on NavMesh).
- Run SearchPhaseTimer; when it hits zero, ease back to Calm (optionally through Suspicious) with a Cooldown timer that blocks instant re-alert from the same noise shard.
- Log why the guard stood down in your debug HUD so playtesters trust the reset.
Common mistake: zero-second search—players never get tension. Aim for 3–8 seconds readable sweep on your greybox scale.
Step 5: Combat stub (scope-safe)
Engaged branch minimum viable slice:
- Rotate toward player pawn or focus actor.
- Optional play montage or AIMoveTo with lunge flag off—prove state, not DPS.
- If player breaks LOS again, fall back to Search, not instant Calm, unless Lesson 1 says otherwise.
Hook damage or arrests in Lesson 9+ if your pillars demand it; here you prove state transitions.
Step 6: Debug and fairness pass
- Simulate three loops: noise only, sight only, noise then break LOS.
- Confirm perception cooldown does not hard-lock guards in Search forever—cap iterations.
- Two guards hearing the same clang should not path-stack; add assign investigation slot or stagger blacklist if needed.
Mini challenge
- Add one audio cue on state entry (soft sting for Suspicious, sharper for Engaged).
- Record time-to-calm after a failed search. Adjust timer until speedrunners cannot abuse a two-second hole.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Insta-calms after combat | Timer not gated by LOS history | Require minimum Engage time |
| Ignores player in face | Engage decorator missing | Fix blackboard branch priority |
| Search circles one point | Random offsets not on NavMesh | Use Get Random Point in Navigable Radius |
| Stuck oscillating Calm/Aware | Two writers on AlertLevel | Single transition authority |
Summary
- State machines are promises to the player about duration and fairness.
- Search needs spatial variety and a hard stop.
- Combat can be non-lethal—keep the graph honest either way.
Further reading
- AI and Behavior Trees in Unreal – selectors, decorators, and blackboard patterns on this site.
- UE 5.5 packaging help – when AI assets explode build size later.
FAQ
Do I need a full animation set for Engaged?
No. Turn-in-place + idle combat sells the state for a vertical slice.
Multiplayer later?
Replicate blackboard-driven states on the server; clients predict locomotion only when your net budget allows.
What if I want non-lethal takedowns?
Treat Engaged as grab attempt with a cooldown and player counter window—same tree, different tasks.
When guards commit to searches and recover with discipline, continue to Lesson 8: Stealth Tools and Gadgets for distractions and temporary disables that stress-test the state machine you wired here. Bookmark this lesson once Engaged never fires without a player-caused perception chain your QA notes can trace.