Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
useEvent subscribes a callback to a named event on any node reference obtained from useRefNode. TypeScript infers the correct callback signature from the node type and the event name, so the compiler will catch mismatched parameters at build time. The subscription is registered when the component mounts and is automatically torn down when the owning node is destroyed — no manual unsubscription is needed.
Signature
Parameters
A node reference created with
useRefNode. The reference determines which node the event is attached to and which event names are available.The name of the event to subscribe to. TypeScript narrows the valid event names to those actually present on the node type
N.The callback function. Its parameter types are inferred from the node type and event name combination, so no explicit typing is needed in most cases.
Return value
void — useEvent does not return a value.
Available events by node type
| Node type | Event name | Callback signature |
|---|---|---|
Collider | colliderEntered | (collider: Collider) => void |
Collider | collided | (collider: Collider) => void |
Collider | colliderExited | (collider: Collider) => void |
Clickable | clicked | (position: Vector2) => void |
Clickable | mouseEntered | () => void |
Clickable | mouseExited | () => void |
Clickable | mouseOver | (position: Vector2) => void |
RayCast | colliderEntered | (collider: Collider) => void |
RayCast | colliderExited | (collider: Collider) => void |
Timer | timeout | () => void |
Timer | timeChanged | (time: number) => void |
| All nodes | started | () => void |
| All nodes | updated | (delta: number) => void |
| All nodes | drawed | (delta: number) => void |
| All nodes | destroyed | () => void |
Examples
Collision detection on an enemy
Enemy.tsx
Hover and click feedback on a button
MenuButton.tsx
Reacting to a timer finishing
Countdown.tsx
Cleanup is automatic. When the component’s owning node is destroyed, every listener registered through
useEvent is removed. You do not need to call .off() or store a reference to the subscription.