# GOAP Authoring

Level: Beginner

## Goal

Set up a Goal-Oriented Action Planning (GOAP) system inside a Flow Graph so that an agent automatically plans and executes a sequence of actions to reach a desired goal state.

## Prerequisites

* A Flow Graph asset exists.
* You can open the Graph Editor.
* A FlowCoreProcess is bound to a GameObject.
* The agent's relevant world-state booleans are stored in a Blackboard.

## Core concepts

* **GoapRoot**: The planner container. Owns all goals and actions. Runs the A\* search and executes the resulting plan.
* **GoapGoal**: A desired world state. The planner tries to achieve it by finding a sequence of actions.
* **GoapAction**: One step the agent can take. Has preconditions (what must be true to run it) and effects (what it changes in the world).
* **Facts / Effects**: Boolean blackboard values that represent world state. The planner reads facts to check conditions and writes effects when an action completes.
* **Priority**: Lower number = higher urgency. Goal with priority 0 is evaluated before goal with priority 1.

## Steps

### 1. Add a GoapRoot node

1. Right-click the canvas → Add Node → GoapRoot.
2. Give the node a unique title (e.g., `CombatPlanner`). This title is the root name used by Instructions.
3. Connect a Flow chain into the GoapRoot's control input to start the planner.

### 2. Add GoapGoal nodes

1. Right-click → Add Node → GoapGoal.
2. Give the node a unique title (e.g., `AttackGoal`).
3. Set **Priority**: 0 = most urgent, higher numbers = lower urgency.
4. In **Desired Conditions**, add one or more GoapBoolFacts:
   * Source: select the blackboard key to read (e.g., `EnemyDead`).
   * Expect: True (the goal is satisfied when EnemyDead = true).
5. Connect the GoapGoal node into the GoapRoot's child list.
6. Optionally wire GoapGoal's **Completed** and **Failed** outputs into Flow.

### 3. Add GoapAction nodes

1. Right-click → Add Node → GoapAction.
2. Give the node a unique title (e.g., `AttackAction`).
3. Set **Cost**: lower cost actions are preferred by the planner (default 1.0).
4. Set **Target Root Name** to match the GoapRoot title (e.g., `CombatPlanner`).
5. In **Preconditions**, add facts that must be true before this action can run (e.g., `InRange = True`).
6. In **Effects**, add facts this action changes when it completes (e.g., `EnemyDead = True`).
7. Wire the **Action Next** output to the logic that performs the actual work (movement, animations, etc.).
8. Connect the GoapAction node into the GoapRoot's child list.

### 4. Activate a goal at runtime

Use the **ActivateGoapGoal** or **ForceActivateGoapGoal** instruction node inside any Flow chain:

* Set **Goal Name** to the title of the GoapGoal node.
* Trigger this instruction when you want the planner to pursue that goal.

### 5. Wire the planner status outputs (optional)

On GoapRoot, connect:

* **Planned**: fires when a plan is found.
* **Goal Changed**: fires when the active goal switches.
* **Replanned**: fires when the planner creates a new plan mid-execution.
* **No Plan**: fires when no valid plan can be found for any active goal.

## Expected result

* Activating a goal causes the planner to search for the cheapest sequence of actions whose combined effects satisfy the goal's desired conditions.
* Actions execute one by one; the planner rechecks preconditions before each action.
* If a blackboard value changes mid-execution, the planner automatically replans.
* When the goal's desired conditions are met, the Goal's **Completed** output fires.

## Common mistakes

* Not connecting GoapAction nodes to the GoapRoot child list — the planner cannot see actions that are not children of the root.
* Setting the same node title on two goals or two actions inside the same root — names must be unique per root.
* Leaving **Target Root Name** blank on a GoapAction — the action will not be included in planning.
* Forgetting to activate a goal — the planner does nothing until at least one goal is active.
* Using a non-boolean blackboard key as a fact source — GOAP facts are boolean only.

## Related

* [GOAP Cookbook](/flow-core-docs/documentation/gameplay-modules/goap-cookbook.md)
* [GOAP Runtime Model](/flow-core-docs/documentation/runtime-guide/goap-runtime.md)
* [GoapRoot](https://github.com/HaikunHuang/FlowCore/blob/main/reference/nodes/node-goap-root.md)
* [GoapGoal](https://github.com/HaikunHuang/FlowCore/blob/main/reference/nodes/node-goap-goal.md)
* [GoapAction](https://github.com/HaikunHuang/FlowCore/blob/main/reference/nodes/node-goap-action.md)
* [Blackboard UI](/flow-core-docs/documentation/editor-guide/blackboard-ui.md)
* [Graph Editor UI](/flow-core-docs/documentation/editor-guide/graph-editor.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flow-core.gitbook.io/flow-core-docs/documentation/gameplay-modules/goap-authoring.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
