Skip to content

What is GOAP?

Goal-Oriented Action Planning (GOAP) is an AI architecture where agents decide what to do by planning backwards from goals rather than following hand-authored decision trees.


The Problem with Traditional AI

Most game AI uses Finite State Machines (FSMs) or Behavior Trees (BTs). Both require you to manually define every transition or branch:

  • FSMs — You define states (Patrol, Chase, Attack) and hand-author every transition between them. Adding a new state means wiring it to every existing state that should connect to it. Complexity grows quadratically.
  • Behavior Trees — You define a tree of conditions and actions. The tree is evaluated top-down every tick. Adding new behaviors means restructuring the tree, and priority is implicit in node order.

Both approaches work well for simple AI, but they become brittle and hard to maintain as the number of behaviors grows.


How GOAP Works

GOAP flips the problem. Instead of telling agents how to behave, you tell them what they want and what each action does:

  1. Goals define a desired world state (e.g., "enemy is dead", "patrol route complete").
  2. Actions declare preconditions (what must be true to use this action) and effects (what the action changes in the world state).
  3. The Planner uses A* search to find a sequence of actions that transforms the current world state into the goal state.

The agent picks the highest-priority valid goal, plans a path of actions to achieve it, and executes them in order. If the world changes mid-plan, the agent can replan.

Example

Suppose an agent has these actions:

Action Preconditions Effects Cost
Move To Target Target position known At target position 2
Attack At target position, Has weapon Enemy is dead 3
Pick Up Weapon At weapon position Has weapon 1

And the goal is "Enemy is dead".

The planner works backwards: - "Enemy is dead" requires Attack - Attack requires "At target position" + "Has weapon" - "At target position" requires Move To Target - "Has weapon" requires Pick Up Weapon (which requires Move To Weapon)

Result: Move To Weapon → Pick Up Weapon → Move To Target → Attack

The agent figured this out on its own — no hand-authored transitions needed.


The RGS Hybrid Approach: FSM + GOAP

Pure GOAP has a scaling problem: as the number of actions and beliefs grows, the A search space can explode. The RGS GOAP Framework solves this with a two-layer hybrid system*:

Layer 1: FSM (Behavioral States)

The top layer is a traditional finite state machine. Each Behavioral State represents a high-level mode of behavior (e.g., Patrol, Alert, Investigate, Combat). Transitions between states are driven by beliefs — boolean conditions evaluated against the blackboard.

Layer 2: GOAP (Planning Within a State)

Within each behavioral state, the GOAP planner selects a goal and finds the best sequence of actions to achieve it. Each state has its own set of actions, goals, and beliefs, keeping the search space small and focused.

Why Hybrid?

  • Tractable planning — Each state only has 3–10 actions instead of 30+, so A* search is fast.
  • Clear high-level structure — Designers can reason about state transitions at a glance.
  • Emergent behavior within states — The planner still finds creative action sequences you didn't hand-author.
  • Burst-compiled — The planner runs as a Unity Job with zero managed allocations.

Data Flow

Here's how data flows through the system every frame:

Sensors ──► Blackboard ──► Planner (Burst A*) ──► Executor
   │              │              │                    │
   │              │         Score Modifiers           │
   │              │         (cost & priority)         │
   │              │              │                    ▼
   │         RecollectionSystem  Goal Selection   Strategy.OnUpdate()
   │         (temporal memory)   ► Preemption     PostProcess chain
   │                             check (0.5s)     HandlePlanCompleted
FSM Transitions (belief-driven, checked on timer ~0.1s)
  1. Sensors read the world (vision cones, proximity checks, waypoints) and write results to the Blackboard.
  2. The Blackboard is the agent's memory — a typed key-value store that everything reads from and writes to.
  3. The Planner evaluates goals, runs A* search over the current state's actions, and produces a plan.
  4. The Executor runs the plan's actions one at a time, calling each action's Strategy (the actual behavior logic).
  5. FSM Transitions check beliefs on a timer and can interrupt the current plan to switch behavioral states.

Key Vocabulary

Term Definition
Brain The top-level ScriptableObject asset that defines an agent's complete AI configuration. Contains states, actions, goals, beliefs, sensors, transitions, and keys.
Behavioral State A high-level mode of behavior (e.g., Patrol, Combat). Contains its own set of actions, goals, and beliefs.
Goal A desired world state the planner tries to achieve. Has a priority and desired conditions.
Action A unit of behavior with preconditions, effects, a cost, and a Strategy that executes it.
Strategy A ScriptableObject that contains the actual execution logic for an action (move, attack, animate).
Post-Process Runs after a strategy succeeds. Used for cleanup, key resets, or follow-up behavior.
Belief A stateless boolean evaluator that reads the blackboard and returns true/false. Used as preconditions, effects, and transition conditions.
Sensor Reads world state (vision, hearing, proximity) and writes results to the blackboard at intervals.
Blackboard Per-agent typed key-value store. The single source of truth for all runtime data.
Slot An abstract key reference on an action. The Key Manifest maps slots to concrete blackboard keys, enabling action reuse across different agent types.
Key Manifest The wiring table in a Brain that maps abstract Slots to concrete Keys.
Score Modifier An AnimationCurve-driven adjuster that dynamically changes action costs or goal priorities based on blackboard values.
Recollection Temporal memory system that tracks stimuli with confidence decay. Agents remember last-known positions and lose track over time.

See Also

  • GOAPAgent — The component that runs the planner and executor
  • Blackboard — The key-value store that drives all decision-making
  • Guard Post Demo — A complete 3-state agent demonstrating the hybrid FSM+GOAP model
  • Glossary — Quick definitions for all terms in the Key Vocabulary table above

What's Next