# World States

***

## Updating World States at Runtime

Write to world state from any script using:

```csharp
// Get the States object for a category and update a key.
WorldStatesRegistry.GetStates("shop")["basketAvailable"] = 0;
```

Any behavior subscribed to `"shop"` will automatically re-plan on the next frame (if `"basketAvailable"` is in that behavior's relevant key set).

> **API note:** The runtime world state class is `WorldStatesRegistry` (static). Access any category with `WorldStatesRegistry.GetStates("categoryName")["key"]`.

***

## Writing from Action Effects

Set **Effects** or **World Effects** on an action in the Inspector. The behavior applies them automatically when the action completes — no code needed. Choose the **Mode** (`Set` / `Add` / `Minus`) to control how the value is applied.

***

## Writing from Code in Actions

```csharp
public override bool PostPerform()
{
    // Direct write from action code.
    WorldStatesRegistry.GetStates("shop")["counterOpen"] = 0;
    return true;
}
```


---

# 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/world-states.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.
