# Quick Start

Get a GOAP agent running in 5 steps.

***

## Step 1 — Set up World States

1. Create an **EngineData** asset in a `Resources` folder: right-click in the Project window → **Create → GOAPEngine → EngineData**.
2. In the Inspector, add one or more **World States** entries. Each entry is a named category containing key-value pairs.

```
Category: "shop"
  basketAvailable = 1
  counterOpen     = 1
  itemAvailable   = 1
```

> `EngineData` registers all world state categories via `RuntimeInitializeOnLoadMethod(BeforeSceneLoad)` — no scene component required and states are always ready before any AIBehavior wakes up.

***

## Step 2 — Create an Agent

1. Add a **NavMeshAgent** to your character GameObject.
2. Add **AIAgent** to the same GameObject — this handles navigation, movement, and target tracking.
3. Add **AIBehavior** to the same GameObject — this is the GOAP brain that plans and executes actions.
4. In the AIBehavior Inspector, configure:
   * **Goal Stacks** — what the behavior wants to achieve and at what priority
   * **Initial States** — the behavior's starting knowledge (e.g. `hasMoney = 1`)
   * **World States To Consider** — category names from WorldStatesControl the behavior should read during planning (e.g. `"shop"`)

> `AIAgent` and `AIBehavior` must be on the same GameObject. `AIBehavior.Awake()` calls `GetComponent<AIAgent>()` automatically — no manual wiring is required.

***

## Step 3 — Create Actions

Use the **Action Creator** window (`Tools > Bee Labs > GOAP Engine > Action Creator`) to scaffold a new action class, then fill in the lifecycle methods.

Alternatively, create a class manually:

```csharp
using GOAPEngine.Core;
using UnityEngine;

[System.Serializable]
public class GetBasket : Action
{
    public GetBasket() { _name = "GetBasket"; }

    public override bool PrePerform()
    {
        // ResolveTarget() is called automatically before this.
        // Return false to abort this entire goal stack.
        return true;
    }

    public override void Perform() { }                    // Called every frame while running

    public override void PerformOnTargetReached() { }     // Called once on arrival

    public override bool PostPerform()
    {
        // Return true to complete the action (effects applied, next action starts).
        // Return false to retry (timer resets).
        return true;
    }
}
```

***

## Step 4 — Add Actions to the Behavior

In the AIBehavior Inspector, expand **Actions Section** and click **"+ Add Action"** to pick from all `Action` subclasses in the project. Then, for each action, configure:

* **Requirements** — preconditions that must be true for this action to be chosen
* **Effects** — behavior state changes applied on completion. Each effect has a **Mode**: `Set` (overwrite), `Add` (increment), or `Minus` (decrement)
* **World Effects** — world state changes applied on completion (by category name), also with **Mode** support
* **Timer** — how many seconds the behavior waits at the target before `PostPerform` fires
* **Target** — optional static Transform the behavior navigates to (can also be resolved automatically from `TargetBinder` components)
* **Target Wait Timeout** — seconds to hold the plan waiting for an available `TargetBinder`. `0` = fail immediately

***

## Step 5 — Run

Press Play. The behavior will:

1. Select the highest-priority achievable goal
2. Plan an action sequence via A\* search
3. Execute each action (navigate → wait → complete → apply effects)
4. Re-plan automatically whenever behavior or world state changes


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://beelabs-dev.gitbook.io/beelabs-docs/goap-engine/quick-start.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.
