Guard Post Demo¶
The Guard Post Demo is a complete, working example included with the framework. It demonstrates a multi-state patrol/alert/investigate AI using optical and auditory sensing, spatial memory, signal-based attacks, and belief-driven state transitions.
Importing the Demo¶
- Open Window > Package Manager.
- Find RGS GOAP Framework in your packages.
- Under Samples, click Import next to the Guard Post Demo.
- The demo scene and assets will be imported into your project.
Note
The demo scene requires a baked NavMesh. If agents don't move after pressing Play, rebake the NavMesh via Window > AI > Navigation.
Overview¶
The demo features guard agents that:
- Patrol between waypoints on a loop
- Become alerted when they see or hear a target
- Investigate the target's last known position using spatial memory
- Attack when in range using the signal system
- Return to patrol when the investigation finds nothing
Brain Structure: 3 Behavioral States¶
State 1: Patrol¶
The default state. The agent moves between waypoints.
Actions:
- Move To Waypoint — Uses
NavMeshMoveStrategyto navigate to the current waypoint position.
Goals:
- Complete Patrol — Desires
IsAtWaypoint = true. The planner selects "Move To Waypoint" to satisfy this.
Sensors active:
- Waypoint Sensor — reads current waypoint from
WayPointManager - Optical Sensor — scanning for targets with vision cone + raycast
- Auditory Sensor — listening for noise events
Transitions out:
CanSeeTarget = true→ Alert (belief-driven FSM transition)HeardSound = true→ Investigate (belief-driven FSM transition)
State 2: Alert¶
The agent has spotted a target and moves to engage.
Actions:
- Move To Target — Uses
NavMeshMoveStrategyto navigate to the target's position. - Attack — Uses
SendSignalStrategy<DamageSignal>to deal damage when in range.
Goals:
- Engage Target — Desires
TargetNeutralized = true. Plans: move to target, then attack.
Sensors active:
- Optical Sensor — continuously tracking the target
- Sphere Sensor — proximity check for attack range
Transitions out:
CanSeeTarget = false(after timeout) → Investigate (target lost, investigate last known position)
State 3: Investigate¶
The agent lost sight of the target and investigates the last known position using spatial memory.
Actions:
- Move To Last Known — Navigates to the recollection system's best-guess position.
- Search Area — Sweeps the investigation area looking for the target.
Goals:
- Complete Investigation — Desires
InvestigationComplete = true. Plans: move to area, then search.
Key feature: The GoapRecollectionSystem provides the last known target position. As time passes, the memory's confidence decays. The agent investigates where it last saw the target, and if the memory expires, the investigation completes and the agent returns to patrol.
Transitions out:
CanSeeTarget = true→ Alert (target re-acquired during investigation)InvestigationComplete = true→ Patrol (nothing found, resume patrol)
Key Systems in Action¶
Spatial Memory (Recollection)¶
The Optical Sensor reports target sightings via WriteVector3(settings, bb, name, position, target). Because the brain has UsesSpatialMemory = true, this routes through ReportStimulus() instead of a direct blackboard write.
The RecollectionSystem tracks the target with confidence decay:
- Fresh sightings have high confidence
- Confidence decays over the configured duration (default 5s)
- The ValidityKey (
HasTargetMemory) istruewhile any memory entry exists - When all entries expire, the ValidityKey becomes
false
This creates organic "search and lose" behavior — the agent investigates where it last saw the target, and gives up when the memory fades.
Score Modifiers¶
The demo uses score modifiers to create dynamic priority:
- Time in Alert drives a score modifier that increases the "Investigate" goal priority over time. If the agent stays in Alert too long without engaging, it transitions to Investigate.
- Distance to target can modify action costs, making closer targets cheaper to pursue.
Signal System¶
The attack action uses SendSignalStrategy<DamageSignal> to deal damage:
- The agent's
DamageSignalProviderproduces aDamageSignalwith damage amount. - The signal is dispatched to the target via
SignalDispatcher.Send(). - The target's
Healthcomponent (implementingISignalListener<DamageSignal>) receives and processes the damage.
Self-Reset Pattern¶
The Investigate state uses the self-reset post-process pattern:
- SetBool
InvestigationComplete = true— satisfies the goal - ClearRecollection on the target position key — cleanup
- SetBool
InvestigationComplete = false— reset for next entry HandlePlanCompletedfires the stored transition → Patrol
This ensures the Investigate state works correctly no matter how it's entered.
Modifying the Demo¶
The demo is designed to be extended:
- Add a fourth state (e.g., Flee) with a health-based transition
- Add more sensors (e.g., a Sphere Sensor for area awareness)
- Tune score modifiers to change how aggressively agents pursue vs investigate
- Add more waypoints to create complex patrol routes
- Adjust recollection duration to make agents remember longer or shorter
See Also
- What is GOAP? — The hybrid FSM+GOAP model this demo demonstrates
- Blackboard — Recollection System — How the temporal memory system works under the hood
- Action Strategies — Self-Reset Pattern — The pattern used by the Investigate state
- Troubleshooting — Fixing state oscillation issues
- Glossary — Quick definitions for Score Modifier, Recollection, and other terms
What's Next¶
- NavMesh Integration — Deep dive into NavMesh movement strategies.
- Inter-Agent Communication — How the signal system works in detail.
- Your First Agent — Build a simpler agent from scratch.