> For the complete documentation index, see [llms.txt](https://docs.allout.game/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allout.game/core-engine-concepts/interactables.md).

# Interactables

<figure><img src="/files/z5fV0hTLmqKSjYOYk2ek" alt=""><figcaption></figcaption></figure>

### The Interactable Component

<figure><img src="/files/XN6p5cmB2FGwYTQmmsAy" alt=""><figcaption></figcaption></figure>

Adding an Interactable component to an entity will automatically show UI when players are within the `radius` you specify.

To respond to the player pressing the interactable, you'll need to write CSL code.

An entity can have more than one `Interactable`. Use `priority` when multiple prompts might be available at the same time.

The most common pattern is:

* Create a class that inherits from `Interactable`
* Call `this.set_listener(this)` in `ao_start`
* Implement `can_use` and `on_interact` on your class

{% hint style="info" %}
If you add a new interactable class in code, you still need to add that component to an entity in the editor (or spawn an entity and add the component at runtime).
{% endhint %}

#### Trash Example

```go
// Get coins for picking up the trash :D 
Trash :: class : Interactable {
    coins: s64 @ao_serialize;
    used: bool;

    ao_start :: method() {
        this.set_listener(this);
        this.set_text("Pick up trash");
        this.set_hold_text("Picking up...");
        required_hold_time = 0.25;
        radius = 1.25;
    }

    can_use :: method(player: Player) -> bool {
        if used return false;
        return true;
    }

    on_interact :: method(player: Player) {
        used = true;
        Economy.deposit_currency(player, "Coins", coins);
        entity.destroy();
    }
}
```

#### Grow Example

An interactable that “grows” an entity (once):

```go
Grow_Button :: class : Interactable {
    scale_multiplier: float @ao_serialize;
    used: bool;

    ao_start :: method() {
        this.set_listener(this);
        this.set_text("Grow");
        radius = 1.25;
        required_hold_time = 0;
    }

    can_use :: method(player: Player) -> bool {
        return !used;
    }

    on_interact :: method(player: Player) {
        used = true;
        new_scale := entity.local_scale * scale_multiplier;
        entity.set_local_scale(new_scale);
        this.set_text("Already used");
    }
}
```

#### Prompt Purchase Example

An interactable that prompts a product purchase:

```go
Buy_Admin_Pass :: class : Interactable {
    product_id: string @ao_serialize;

    ao_start :: method() {
        this.set_listener(this);
        this.set_text("Buy Admin Pass");
        radius = 1.25;
    }

    can_use :: method(player: Player) -> bool {
        // Example gate: hide if already owned (game pass)
        return !Purchasing.owns_product(player, product_id);
    }

    on_interact :: method(player: Player) {
        Purchasing.prompt_purchase(player, product_id);
    }
}
```

### API Reference

```go
Interactable :: class : Component {
    // Prompt text (tap interaction)
    get_text :: method() -> string;
    set_text :: method(text: string);

    // Prompt text while holding (for hold-to-interact)
    get_hold_text :: method() -> string;
    set_hold_text :: method(text: string);

    // Wire a listener object that implements:
    // - can_use(player: Player) -> bool
    // - on_interact(player: Player)
    // - on_holding(player: Player) [optional]
    set_listener :: method(new_listener: Component);

    // Common fields (set in editor or in code)
    offset: v2;
    prompt_offset: v2;
    radius: float;
    required_hold_time: float;
    priority: s64;
}
```

### Optional player hooks (global rules)

You can also implement these on your `Player` class to enforce game-wide rules (e.g. can't use interactables before respawning):

```go
Player :: class : Player_Base {
    ao_can_use_interactable :: method(interactable: Interactable) -> bool {
        return true;
    }

    ao_on_interactable_used :: method(interactable: Interactable) {
    }

    ao_on_holding_interactable :: method(interactable: Interactable) {
    }
}
```


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.allout.game/core-engine-concepts/interactables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
