githubEdit

Input Event Methods

Reference for pointer, touch, and controller input events

Handle pointer/touch/controller interactions on your components.

:::tip Cross-Platform Input These events work across desktop, mobile, and VR—no need to handle different input types separately! :::


Event Methods

Method
Parameters
When Called

onPointerEnter

args: PointerEventData

Cursor starts hovering (object or children)

onPointerMove

args: PointerEventData

Cursor moves over object (or children)

onPointerExit

args: PointerEventData

Cursor stops hovering

onPointerDown

args: PointerEventData

Cursor pressed (mouse/touch down)

onPointerUp

args: PointerEventData

Cursor released

onPointerClick

args: PointerEventData

Cursor clicked (down + up on same object)


PointerEventData

The event parameter provides detailed information:

interface PointerEventData {
    // The point where the raycast hit the object
    point: Vector3;

    // The object that was hit
    object: Object3D;

    // Screen-space pointer position (0-1 range)
    pointerId: number;

    // Mouse button or touch index
    button: number;

    // Original browser event
    event: PointerEvent;
}

Example: Simple Click Handler


Example: Hover Effects


Example: Drag and Drop


Global Input Events

Subscribe to input events globally (not just on specific objects):


Polling Input State

Check input state every frame:


Browser Events

You can also subscribe to native browser events:

:::warning When using browser events directly, you need to handle platform differences yourself (mouse vs touch vs VR controllers). Needle Engine input events handle this automatically. :::


Requirements

For input events to work:

  1. Object must be visible (visible = true)

  2. Object's layer must not be set to "Ignore Raycast"

  3. GameObject must have a collider - Only required when using physics-based raycasting. For regular pointer events, a mesh with geometry is sufficient.


Last updated