# Troubleshooting

Find the problem you see, then check its causes in order.

## Starting a Session

| Problem | Cause | Fix |
| --- | --- | --- |
| VR or AR is never available, and the button to enter it never shows | The page isn't in a secure context | Serve it over HTTPS, or from `localhost`. See [Testing on a Device](https://developer.playcanvas.com/user-manual/xr/testing.md#testing-on-a-device) |
| | The page is in an iframe that doesn't allow XR | Add `allow="xr-spatial-tracking"` to the `<iframe>`. In debug builds, the engine logs a warning when it skips checking availability for this reason |
| | The graphics device uses WebGPU, in a browser that can't present WebGPU to a headset | Use WebGL 2. See [Choosing a Graphics Device](https://developer.playcanvas.com/user-manual/xr/using-webxr.md#choosing-a-graphics-device) |
| | The device doesn't support the session type, such as AR on an Apple Vision Pro | See [Platforms](https://developer.playcanvas.com/user-manual/xr/platforms.md) |
| | The code checked `isAvailable` once, as the application started | The answer arrives asynchronously. Follow the `available` event. See [Checking Availability](https://developer.playcanvas.com/user-manual/xr/sessions.md#checking-availability) |
| | The application has no XR manager, so `app.xr` is `null` | Add `options.xr = XrManager` to the `AppOptions` of an application created with `AppBase` |
| The session doesn't start when the button is selected | The session was requested outside the handler of a user action, such as after an `await` or from a timer | Call `startXr`, or fire the event that starts the session, in the click handler itself |
| | It asks for a reference space that the device doesn't support, such as `bounded-floor` | Start with `local-floor`. Pass a callback to `startXr` to see the error. See [Reference Spaces](https://developer.playcanvas.com/user-manual/xr/sessions.md#reference-spaces) |
| | A session is already running or starting | Only one session can run at a time. The callback is passed `XR session is already started` or `XR session is already starting` |
| A feature such as plane detection is unavailable during the session | The session was started without the option that asks for it | Pass the option to `startXr`. The `XrSession` script starts sessions without options. See [Options and Features](https://developer.playcanvas.com/user-manual/xr/sessions.md#options-and-features) |
| | The device or the user didn't grant it | Check `app.xr.session.enabledFeatures`, and see [Platforms](https://developer.playcanvas.com/user-manual/xr/platforms.md) |

## In the Session

| Problem | Cause | Fix |
| --- | --- | --- |
| Setting the camera's position or rotation has no effect | The headset sets the camera's local position and rotation every frame | Move the camera's parent, the rig. See [The Camera and Its Rig](https://developer.playcanvas.com/user-manual/xr/sessions.md#the-camera-and-its-rig) |
| The user is too high, too low or inside the floor | The session uses `local` space, whose origin is at the user's head | Use `local-floor`, whose origin is on the floor |
| | The rig isn't on the floor of the scene | Put the rig at the height of the floor. The `XrSession` script puts it at y = 0 when a session starts |
| The user starts in a different place, or facing another way, from the page's view | The `XrSession` script moves the rig below the camera, facing where it faces | Place and turn the camera, before the session starts, where the user should start |
| The camera doesn't return to where it was after a session | Nothing restores it, unless the `XrSession` script is on the rig | Add `XrSession`, or save and restore the camera and rig yourself in `start` and `end` handlers |
| Objects disappear when brought close to the eyes | The camera's near clip distance is too large | Set `nearClip` to between 0.01 and 0.1 |
| The button that enters XR stays hidden after a session ends | Its `end` handler checks `app.xr.active`, which is still `true` while `end` handlers run | Show the button in the `end` handler without checking `active`, as [Getting Started](https://developer.playcanvas.com/user-manual/xr/using-webxr.md#your-first-vr-scene) does. See [Ending a Session](https://developer.playcanvas.com/user-manual/xr/sessions.md#ending-a-session) |
| The application keeps running behind the system menu | It doesn't react to the session's visibility | Pause it on the `visibility:change` event. See [Visibility](https://developer.playcanvas.com/user-manual/xr/sessions.md#visibility) |

## Input

| Problem | Cause | Fix |
| --- | --- | --- |
| No controllers or hands are drawn | Nothing draws them: the engine reports their poses, but doesn't draw models | Add the `XrControllers` script to the rig. See [Controller Models](https://developer.playcanvas.com/user-manual/xr/controllers.md#controller-models) |
| | `XrControllers` can't download the models | It loads them from a CDN, so the device needs internet access. Set its `basePath` attribute to host the models yourself |
| | `XrControllers` was added during the session | It only draws the input sources that are added after it starts. Add it before the session starts. `XrNavigation` is the same |
| Controllers are drawn in the wrong place | Their models aren't children of the rig, and are placed with local poses | Use world positions and rotations, `getPosition()` and `getRotation()`, or add the models under the rig. See [Tracking Space](https://developer.playcanvas.com/user-manual/xr/sessions.md#tracking-space) |
| `getPosition()` and `getRotation()` return `null` for a hand | Tracked hands have no grip pose | Use the poses of the hand's joints, such as its wrist. See [Joints](https://developer.playcanvas.com/user-manual/xr/hand-tracking.md#joints) |
| Reading a thumbstick gives `undefined` | The input source is a hand, or a controller without a thumbstick, and its gamepad leaves the axes out | Check the length of `axes`, or read it with `?? 0`. See [Buttons and Thumbsticks](https://developer.playcanvas.com/user-manual/xr/controllers.md#buttons-and-thumbsticks) |
| Selecting a button or menu item also teleports the user | `XrNavigation` teleports at the end of every select on valid ground | Turn teleporting off while a menu is open or a ray points at the interface. See [Teleporting and Menus](https://developer.playcanvas.com/user-manual/xr/locomotion.md#teleporting-and-menus) |
| Teleports land behind walls, or fall through steps | The `castRay` function returns `null` for walls, so the arc carries on, or casts from where the last segment ended | See [Landing on Your Geometry](https://developer.playcanvas.com/user-manual/xr/locomotion.md#landing-on-your-geometry) |
| A grabbed object stays behind, or shakes, when it has a rigid body | Physics moves dynamic bodies, and overrides the transform that your code sets | Make the body kinematic while it is held. See [Throwing](https://developer.playcanvas.com/user-manual/xr/pointing-and-grabbing.md#throwing) |

## In AR

| Problem | Cause | Fix |
| --- | --- | --- |
| The background is black or a color, not the real world | The camera clears to an opaque color, or a skybox is drawn | Give the camera a transparent clear color, `new Color(0, 0, 0, 0)`, and hide the skybox layer. The `XrSession` script does both during AR sessions |
| Content placed on hit test results, planes or anchors is in the wrong place, or drifts as the user moves | These poses are in tracking space, and the rig has moved away from the scene's origin | Add the content as a child of the rig, and set its local position and rotation. See [Tracking Space](https://developer.playcanvas.com/user-manual/xr/sessions.md#tracking-space) |
| The background turns opaque during an AR session in React | `<Camera>` sets the clear color from its `clearColor` prop each time it renders, over the transparent color that `XrSession` sets | Keep the component from rendering during the session, or give `clearColor` a transparent value during AR sessions. See [Your First AR Scene](https://developer.playcanvas.com/user-manual/xr/ar.md#your-first-ar-scene) |
| Hit tests return no results on a phone | The phone hasn't found any surfaces yet | Ask the user to move the phone slowly over the floor for a few seconds. See [Starting a Hit Test](https://developer.playcanvas.com/user-manual/xr/ar/hit-testing.md#starting-a-hit-test) |
| A controller's or a hand's hit test source returns no results | `hitTestStart()` uses hit tests for transient input, which WebXR only gives for transient input sources, such as taps | Test the ray against detected planes or meshes. See [Hit Tests from Screen Taps](https://developer.playcanvas.com/user-manual/xr/ar/hit-testing.md#hit-tests-from-screen-taps) |
| Creating an anchor from a hit test result fails with `XRFrame access outside the callback that produced it is invalid` | The result belongs to an earlier frame, such as one kept for a later select | Create the anchor in the hit test source's `result` handler. See [Creating Anchors](https://developer.playcanvas.com/user-manual/xr/ar/anchors.md#creating-anchors) |
| Each anchor gets two objects, or the callback of `create()` is never called | In engine 2.24, an anchor from a hit test result, or restored, fires `add` twice, and `create(position, rotation)` doesn't call its callback when it succeeds | Follow anchors from hit test results, and restored anchors, from their callbacks, and others from `add`. See [Creating Anchors](https://developer.playcanvas.com/user-manual/xr/ar/anchors.md#creating-anchors) |
| Light estimation is never available | It doesn't run until it's started | Call `app.xr.lightEstimation.start()` in the session's `start` handler. See [Starting Light Estimation](https://developer.playcanvas.com/user-manual/xr/ar/light-estimation.md#starting-light-estimation) |
| `getDepth()` always returns `null` | The session's depth sensing uses the GPU, as on a Meta Quest | Read the depth texture in a shader instead. See [The Depth Texture](https://developer.playcanvas.com/user-manual/xr/ar/depth-sensing.md#the-depth-texture) |
| Virtual objects show in front of real objects that should hide them | Nothing hides them: the scene is drawn over the real world | Draw the room's meshes into the depth buffer, or use depth sensing. See [Hiding Objects Behind Real Ones](https://developer.playcanvas.com/user-manual/xr/ar/mesh-detection.md#hiding-objects-behind-real-ones) |

## Performance

| Problem | Cause | Fix |
| --- | --- | --- |
| The view is blurry, or text is hard to read | The session renders below the device's recommended resolution | Set `maxPixelRatio` to `window.devicePixelRatio`. See [Resolution](https://developer.playcanvas.com/user-manual/xr/optimizing-webxr.md#resolution) |
| The view judders or smears as the user looks around | Frames take longer than the headset's frame time | See [Performance](https://developer.playcanvas.com/user-manual/xr/optimizing-webxr.md), and lower the [frame rate](https://developer.playcanvas.com/user-manual/xr/optimizing-webxr.md#frame-rate) or the resolution |
| Fixed foveation has no effect | The graphics device uses anti-aliasing with WebGL | Create the device with `antialias: false`. See [Fixed Foveation](https://developer.playcanvas.com/user-manual/xr/optimizing-webxr.md#fixed-foveation) |

## See Also

- [Testing and Debugging](https://developer.playcanvas.com/user-manual/xr/testing.md) - Emulators, devices and remote debugging
- [Sessions](https://developer.playcanvas.com/user-manual/xr/sessions.md) - The session lifecycle, reference spaces and the camera rig
- [Troubleshooting](https://developer.playcanvas.com/user-manual/user-interface/troubleshooting.md) in the User Interface section - For panels and buttons that don't respond in XR
