# Trigger volumes

Trigger volumes is a type of volume that you can place within your game world to detect when other objects or characters enter or exit it. Trigger volumes are commonly used in games for various purposes, such as triggering events or activating gameplay mechanics.

## Creating trigger volumes

### TriggerVolumeActor

A trigger volume actor can be placed as an object in your scene. You can find it in the asset browser under actors. You can then refer to the trigger volume actor by adding it as a parameter to another actor.

### TriggerVolumeComponent

A trigger volume can be created by attaching a TriggerVolumeComponent to an actor. The trigger volume is a box so you need to provide the dimensions of it.

## Handling trigger volume events

Whenever an actor enters or exists a trigger volume, you can trigger some functionality. In the example below, every time the Character actor overlaps with a Coin actor, it increases the number of collected coins bye one and then removes the coin actor from the world.

```typescript
@Actor()
class Character extends BaseActor {
    private physicsSystem = inject(PhysicsSystem)
    private world = inject(World)
    
    collectedCoins: number = 0

    onInit() {
        this.physicsSystem.onBeginOverlapWithActorType(this, Coin)
            .subscribe(coin => {
                this.collectedCoins++
                world.remove(coin)                
            })
    }
}

@Actor()
class Coin extends BaseActor {
    private triggerVolume = attach(TriggerVolumeComponent, { 
        dimensions: new Vector3(1, 1, 1) 
    })
}
```


---

# 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.hology.app/gameplay/trigger-volumes.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.
