# XrHitTestSource

Class · extends [`EventHandler`](https://api.playcanvas.com/engine/classes/EventHandler.md) · category: XR

Source: https://github.com/playcanvas/engine/blob/b5b983982a9860d21e0c1dafb2f85f72e2c01afb/src/framework/xr/xr-hit-test-source.js#L40

Represents XR hit test source, which provides access to hit results of real world geometry from
AR session.

```javascript
// start a hit test from a viewer origin forward
app.xr.hitTest.start({
    spaceType: XRSPACE_VIEWER,
    callback: (err, hitTestSource) => {
        if (err) return;
        // subscribe to hit test results
        hitTestSource.on('result', (position, rotation, inputSource, hitTestResult) => {
            // position and rotation of hit test result
        });
    }
});
```

## Methods

### remove

```ts
remove(): void
```

Stop and remove hit test source.

## Events

### EVENT_REMOVE

```ts
static EVENT_REMOVE: string = 'remove'
```

Fired when [XrHitTestSource](https://api.playcanvas.com/engine/classes/XrHitTestSource.md) is removed.

**Example**

```ts
hitTestSource.once('remove', () => {
    // hit test source has been removed
});
```

### EVENT_RESULT

```ts
static EVENT_RESULT: string = 'result'
```

Fired when the hit test source receives new results. It provides transform information that
tries to match real world geometry. Callback provides the [Vec3](https://api.playcanvas.com/engine/classes/Vec3.md) position, the
[Quat](https://api.playcanvas.com/engine/classes/Quat.md) rotation, the [XrInputSource](https://api.playcanvas.com/engine/classes/XrInputSource.md) (if it is a transient hit test source)
and the [XRHitTestResult](https://developer.mozilla.org/en-US/docs/Web/API/XRHitTestResult)
object that is created by WebXR API.

**Example**

```ts
hitTestSource.on('result', (position, rotation, inputSource, hitTestResult) => {
    target.setPosition(position);
    target.setRotation(rotation);
});
```

## Inherited from [EventHandler](https://api.playcanvas.com/engine/classes/EventHandler.md)

- `fire(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any, arg6?: any, arg7?: any, arg8?: any): EventHandler`
- `hasEvent(name: string): boolean`
- `off(name?: string, callback?: HandleEventCallback, scope?: any): EventHandler`
- `on(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
- `once(name: string, callback: HandleEventCallback, scope?: any): EventHandle`
