Skip to content

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

  1. Open Window > Package Manager.
  2. Find RGS GOAP Framework in your packages.
  3. Under Samples, click Import next to the Guard Post Demo.
  4. 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 NavMeshMoveStrategy to 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 = trueAlert (belief-driven FSM transition)
  • HeardSound = trueInvestigate (belief-driven FSM transition)

State 2: Alert

The agent has spotted a target and moves to engage.

Actions:

  • Move To Target — Uses NavMeshMoveStrategy to 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 = trueAlert (target re-acquired during investigation)
  • InvestigationComplete = truePatrol (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) is true while 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:

  1. The agent's DamageSignalProvider produces a DamageSignal with damage amount.
  2. The signal is dispatched to the target via SignalDispatcher.Send().
  3. The target's Health component (implementing ISignalListener<DamageSignal>) receives and processes the damage.

Self-Reset Pattern

The Investigate state uses the self-reset post-process pattern:

  1. SetBool InvestigationComplete = true — satisfies the goal
  2. ClearRecollection on the target position key — cleanup
  3. SetBool InvestigationComplete = false — reset for next entry
  4. HandlePlanCompleted fires 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's Next