Your First Agent¶
This tutorial walks you through creating a working GOAP agent from scratch. By the end, you'll have an agent that patrols between waypoints using the framework's built-in components.
Prerequisites¶
- The RGS GOAP Framework is installed in your Unity project.
- A scene with a NavMesh baked (for movement).
- A GameObject with a
NavMeshAgentcomponent that will become your AI agent.
Step 1: Create a Brain¶
In the Project window:
- Right-click in your project folder.
- Select
Create > RGS > GOAP > Brain. - Name it GuardBrain.
This is the top-level container for your agent's AI — it holds all states, sensors, keys, and transitions. See GoapBrainSO for the full reference.
Step 2: Create Blackboard Keys¶
Your agent needs keys to store data. Create these:
Create > RGS > GOAP > Blackboard > Slot— name it WaypointPosition (type: Vector3)Create > RGS > GOAP > Blackboard > Slot— name it IsAtWaypoint (type: Boolean)
These keys will hold the current waypoint position and whether the agent has arrived.
Step 3: Create Beliefs¶
Beliefs are the conditions the planner reasons about.
Create > RGS > GOAP > Beliefs > Bool Check— name it Belief_IsAtWaypoint.Create > RGS > GOAP > Beliefs > Vector3 Is Set— name it Belief_HasWaypoint.
These will check whether the agent is at its waypoint and whether a waypoint position exists on the blackboard.
Step 4: Create an Action¶
Actions are the behaviors the planner can choose from.
Create > RGS > GOAP > Action— name it Action_MoveToWaypoint.- In the Inspector, assign the built-in NavMeshMoveStrategy as the Strategy.
- Configure the strategy settings:
- Set
TargetKeyIdto reference the WaypointPosition slot. - Set
MoveSpeedto your desired speed (e.g.,3.5). - Set
StoppingDistanceto match your NavMeshAgent's stopping distance (e.g.,0.5).
- Set
- Add a Precondition: Belief_HasWaypoint =
true(the agent needs a waypoint to move to). - Add an Effect: Belief_IsAtWaypoint =
true(after moving, the agent is at the waypoint). - Set Cost to
1.
What this looks like in code
The Inspector steps above configure a GoapActionInstance with these values:
// This is what the GOAP Hub creates for you behind the scenes.
// You don't need to write this code — it's shown for understanding.
// Action: Move To Waypoint
// Strategy: NavMeshMoveStrategy
// TargetKeyId: → WaypointPosition slot
// MoveSpeed: 3.5
// StoppingDistance: 0.5
// Precondition: Belief_HasWaypoint == true
// Effect: Belief_IsAtWaypoint == true
// Cost: 1
The planner reads: "If a waypoint exists (precondition), I can move there (strategy) and I'll be at the waypoint (effect)."
Step 5: Create a Goal¶
Create > RGS > GOAP > Goal— name it Goal_Patrol.- Set Priority to
1.0. - Add a Desired State condition: Belief_IsAtWaypoint =
true.
This tells the planner: "I want to be at a waypoint. Find me a plan to get there."
Step 6: Create a Behavioral State¶
Create > RGS > GOAP > Behavioral State— name it State_Patrol.- Add Action_MoveToWaypoint to its Actions list.
- Add Goal_Patrol to its Goals list.
- Add both beliefs (Belief_IsAtWaypoint and Belief_HasWaypoint) to its Beliefs list.
Step 7: Wire the Brain¶
- Select your GuardBrain asset.
- Click Open GOAP Suite (or open it from
Tools > RGS GOAP > Welcome & Setup). - In the Library panel:
- Add State_Patrol to the Brain's States list.
- Set it as the Default State.
- Add your Waypoint Sensor to the Brain's Sensors list.
- In the Key Manifest, wire the slots:
- Map the WaypointPosition slot to your WaypointPosition key.
- Map the IsAtWaypoint slot to your IsAtWaypoint key.
- Click Validate to check for errors.
Step 8: Set Up the Agent GameObject¶
- Select your agent GameObject in the scene.
- Add the
GoapAgentcomponent. (SensorControllerandGoapAgentContextare added automatically.) - Assign your GuardBrain asset to the Brain field.
- Add a
WayPointManagercomponent. - Create empty GameObjects in the scene to use as waypoints.
- Drag them into the WayPointManager's Waypoints list.
- Enable Loop if you want the agent to cycle through waypoints continuously.
Step 9: Add a Waypoint Sensor¶
Create > RGS > GOAP > Sensors > Waypoint Sensor.- In the Brain's sensor list, add this sensor.
- Map its outputs:
- WaypointPosition output → your WaypointPosition key
- IsAtWaypoint output → your IsAtWaypoint key
The sensor reads from the WayPointManager and writes the current waypoint position and arrival status to the blackboard.
Step 10: Press Play¶
- Enter Play mode.
- The agent should begin moving to the first waypoint.
- When it arrives, the WayPointManager advances to the next waypoint, the sensor updates the blackboard, and the planner creates a new plan to move to the next position.
Open the GOAP Hub to see the plan executing in real time.
What you should see
- The agent moves smoothly along the NavMesh toward the first waypoint
- In the GOAP Hub, the active plan shows: Goal_Patrol → Action_MoveToWaypoint
- The agent pauses briefly at each waypoint, then the sensor updates and the planner produces a new plan to the next waypoint
- If Loop is enabled on the WayPointManager, the agent cycles through waypoints continuously
Common issues
- Agent doesn't move: Check that the NavMesh is baked (
Window > AI > Navigation > Bake). Also verify the agent's GameObject has aNavMeshAgentcomponent. - Agent spins in place: Ensure
StoppingDistanceon the strategy settings matches or is slightly larger than theNavMeshAgent's stopping distance. - Plan never appears: Open the GOAP Hub and click Validate. Check that all slots are wired in the Key Manifest and that Goal_Patrol has
Priority > 0. - "Missing Script" on strategy: Verify your
.asmdefreferencesRGS.GOAP.Core. See Troubleshooting.
What You Built¶
Your agent now has:
- A Brain with one behavioral state
- A Waypoint Sensor reading patrol points into the blackboard
- A Move To Waypoint action using the built-in NavMeshMoveStrategy
- A Patrol goal driving the planner to keep the agent moving
Tip
This is the simplest possible agent. To build more complex AI, add more states (Alert, Combat), more actions (Investigate, Attack), sensors (Optical, Sphere), and transitions between states. See the Guard Post Demo for a complete multi-state example.
See Also
- GOAPAgent — Full reference for the
GoapAgentcomponent and all its settings - Blackboard — How the key-value store works under the hood
- What is GOAP? — Understand the planning model behind what you just built
- Glossary — Quick definitions for Brain, Belief, Strategy, and other terms
What's Next¶
- Guard Post Demo — A complete 3-state agent with vision, memory, and combat.
- GOAP Hub Overview — Master the visual editor.
- Action Strategies — Create custom strategies for unique behaviors.