# API

**Assembly:** `Spark.Interactables`

The Interactables plugin does not expose a central interface. It provides the `InteractableObjectEntity` component and supporting infrastructure for creating interactive objects in the scene.

## InteractableObjectEntity

MonoBehaviour implementing `IInteractable`. The primary component for interactive objects.

### Configuration

| Field                          | Type                         | Description                                   |
| ------------------------------ | ---------------------------- | --------------------------------------------- |
| `displayName`                  | string                       | Interaction prompt text (default: "Interact") |
| `indicatorYOffset`             | float                        | Vertical offset for UI indicator              |
| `indicatorDistance`            | float                        | Distance at which indicator appears           |
| `canInteractDistance`          | float                        | Distance at which interaction is possible     |
| `interactionRequirements`      | List\<RequirementGroupEntry> | Conditions for interaction                    |
| `showUIWhenRequirementsNotMet` | bool                         | Show indicator even if requirements fail      |
| `canInteractHighlight`         | GameObject                   | Highlight object when interactable            |
| `onInteractionTriggers`        | List\<TriggerConfiguration>  | Triggers executed on interact                 |
| `allowMultipleInteractions`    | bool                         | Can interact more than once                   |
| `onInteract`                   | UnityEvent                   | Unity Event callback                          |

### State Properties

```csharp
bool HasInteracted       // True if already interacted (one-shot tracking)
bool IsInIndicatorRange  // Player is close enough to see indicator
bool IsInInteractRange   // Player is close enough to interact
bool IsTargeted          // Player is looking at this object
bool MeetsRequirements   // All requirements are satisfied
bool CanInteract         // Computed: in range, targeted, meets requirements,
                         // and allows interaction
```

### Methods

```csharp
void SetInIndicatorRange(bool inRange)
void SetInInteractRange(bool inRange)
void SetTargeted(bool targeted)
void UpdateRequirementsCheck()
// Validates requirements using IRequirementsPlugin.

void Interact(GameObject interactor)
// Executes the interaction: fires triggers, invokes UnityEvent,
// marks as interacted.

void ResetInteraction()
// Resets HasInteracted, allowing re-interaction.
```

### InteractionEventData

Data passed when an interaction occurs.

| Field                | Type       | Description                   |
| -------------------- | ---------- | ----------------------------- |
| `InteractableEntity` | GameObject | The interactable object       |
| `InteractorEntity`   | GameObject | The player/entity interacting |
| `InteractionTime`    | float      | When the interaction happened |

## IInteractable

Interface that all interactable objects implement.

```csharp
public interface IInteractable
{
    string DisplayName { get; }
    bool CanInteract { get; }
    void Interact(GameObject interactor);
}
```

## Dependencies

The Interactables plugin integrates with:

* **Triggers Plugin** for executing trigger lists on interaction
* **Requirements Plugin** for validating interaction conditions
* **InteractablesManager** for managing UI indicator display and targeting

## Usage

### Setting Up an Interactable

1. Add `InteractableObjectEntity` to a GameObject
2. Configure the display name and distances
3. Add triggers to `onInteractionTriggers`
4. Optionally add requirement groups to restrict interaction
5. Optionally assign a highlight object

### Custom Interactable

```csharp
public class TreasureChest : MonoBehaviour, IInteractable
{
    [SerializeField] private string chestName = "Treasure Chest";
    private bool isOpened = false;

    public string DisplayName => chestName;
    public bool CanInteract => !isOpened;

    public void Interact(GameObject interactor)
    {
        if (isOpened) return;
        isOpened = true;
        // Grant loot, play animation, etc.
    }
}
```

### Checking Interaction from Code

```csharp
var interactable = targetObject.GetComponent<InteractableObjectEntity>();
if (interactable != null && interactable.CanInteract)
{
    interactable.Interact(playerObject);
}
```


---

# 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://docs.sparkframework.dev/documentation/developer-guide/plugins/npcs/api.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.
