# TargetBinder

**TargetBinder** is a MonoBehaviour you attach to any scene object (a tree, workbench, chair, etc.) to make it a discoverable navigation target for GOAP behaviors. Binders self-register with `TargetBinderRegistry` on `OnEnable` and unregister on `OnDisable` — zero manual management.

***

## Inspector Fields

| Field                  | Description                                                                                                                                                                                                                      |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Name**               | Only the behavior whose `GameObject.name` exactly matches may use this target. Leave empty for any behavior.                                                                                                                     |
| **Group**              | Only behaviors whose `Group` field matches may use this target. Leave empty for any group.                                                                                                                                       |
| **Compatible Actions** | List of action class names (e.g. `"CollectWood"`) that may use this target. Leave empty for any action type.                                                                                                                     |
| **Priority**           | Selection weight. Higher-priority targets beat lower-priority ones at equal distance (score = distance / priority).                                                                                                              |
| **Is Shared**          | When enabled, multiple behaviors can target this simultaneously. Resource locking (`IsAvailable = false`) is ignored — the slot is never marked occupied. Useful for waypoints, patrol spots, and any non-exclusive destination. |
| **Is Available**       | Whether this binder can currently be claimed. Managed automatically by the engine; set from code to implement custom slot-occupied logic. Always `false` when the GameObject is disabled.                                        |

***

## Group

Set `_group` on the `AIBehavior` component to group behaviors. Any TargetBinder with a matching `Group` filter will only accept behaviors from that group. This lets you partition targets: e.g. `"Woodcutters"` and `"Builders"` can have different resource pools without code.

***

## Placing TargetBinders

1. Select the world object you want behaviors to navigate to
2. `Add Component → GOAP Engine → Target Binder`
3. Set filters as needed (leave all empty for no filtering)
4. Set **Compatible Actions** to limit which actions may claim this binder (e.g. `CollectWood`)
5. Enable **Is Shared** if multiple behaviors can use this target at once

No code changes to the behavior or action are required — call `SelectBestBinder()` from `ComputeCost()` to query the registry automatically at the start of each planning cycle.

***

## TargetBinderRegistry

`TargetBinderRegistry` is a static class that holds all active binders. It is updated automatically via `OnEnable`/`OnDisable`. You generally do not need to call it directly, but the following members are available for tooling:

| Member                            | Description                                                                                   |
| --------------------------------- | --------------------------------------------------------------------------------------------- |
| `GetClosest(behavior, targetTag)` | Returns the nearest available binder matching the tag filter (or all binders if tag is empty) |
| `GetRandom(behavior, targetTag)`  | Returns a random available binder matching the tag filter                                     |
| `All`                             | All registered binders (including unavailable ones). For editor tooling and debugging.        |


---

# 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/target-binder.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.
