XR
XR, or extended reality, covers virtual reality (VR), in which a headset replaces the world around the user with your scene, and augmented reality (AR), in which your scene appears in the real world. PlayCanvas applications run in XR through WebXR, the web's API for immersive devices, in the browsers of headsets such as the Meta Quest and Apple Vision Pro, of Android phones, and of computers with a PC VR headset. There's nothing to install: the user opens a web page and selects a button to enter XR.

XR works the same way whichever way you build: in the Editor, directly against the engine, in PlayCanvas React and in Web Components. Each page in this section explains a concept once, and shows how to apply it on each of those surfaces where they differ.
How XR Works
An XR application starts as an ordinary web page, which renders to a canvas. Then:
- The user enters a session. A button on the page asks the browser for an immersive session, VR or AR, and the device takes over the display. When the user leaves the session, the page is shown again. See Sessions.
- The headset drives a camera. Every frame, the engine moves the session's camera to the pose of the user's head, relative to the camera's parent entity, its rig. To move the user through the scene, move the rig. See The Camera and Its Rig.
- The scene is rendered once for each eye. A headset shows each eye its own image, from a position a few centimeters from the other's, which gives the scene depth. The engine renders both from the one camera. A phone in AR shows a single view.
- Controllers and hands are input sources. Each has a ray that points into the scene, and a primary action such as pulling a trigger or pinching. See Input Sources.
- In AR, the real world shows through. The camera clears to transparent instead of a color, and the device composites your scene over its view of the room. AR sessions can also find surfaces in the room and place content on them. See AR.
Building Blocks
The engine's XR manager does the work of a session, and a set of scripts that ship with the engine add the usual behavior of an XR application on top of it:
| Building block | Role |
|---|---|
XrManager (app.xr) | Checks which session types are available, starts and ends sessions, drives the camera, and gives access to input and every XR feature |
CameraComponent#startXr and endXr | Start and end a session on a camera |
XrSession script | Starts and ends sessions in response to application events, places the rig when a session starts, and makes the camera transparent in AR. See Sessions |
XrControllers script | Draws a model of each controller and hand. See Controllers |
XrNavigation script | Moves the user by teleporting and with the thumbsticks. See Locomotion |
XrMenu script | A menu on the user's hand or controller. See UI in XR |
XrManipulation script | Lets the user grab the scene with both hands to move, turn and scale it. See Pointing and Grabbing |
The scripts are in the playcanvas package on npm, under scripts/esm/xr/, and in the engine's GitHub repository. Getting Started adds them to an application on each surface.
Features
What a session can do depends on the device and its browser. Each feature is a part of app.xr with its own page. Check that a feature is available once a session has started, and give the user a way to carry on without it. See Platforms for the features of each device.
| Feature | VR | AR | What it does |
|---|---|---|---|
| Input Sources | ✅ | ✅ | Controllers, hands, gaze and screen taps, with their rays and buttons |
| Hand Tracking | ✅ | ✅ | The position of each joint of the user's hands |
| Hit Testing | ✅ | Casts a ray at the real world, to place content on its surfaces | |
| Anchors | ✅ | Keeps content in place in the real world as the device's understanding of the room improves, and between sessions | |
| Plane Detection | ✅ | Floors, walls, tables and other flat surfaces in the room | |
| Mesh Detection | ✅ | The shape of the room and its furniture, as meshes | |
| Depth Sensing | ✅ | The distance to the real world at each pixel, to hide content behind real objects | |
| Light Estimation | ✅ | The direction, color and intensity of the room's light | |
| Camera Access | ✅ | The image from the device's camera, as a texture | |
| Image Tracking | ✅ | The position of printed images that you provide | |
| DOM Overlay | ✅ | HTML shown over AR on a phone |
The engine also gives access to the device's frame rate and fixed foveation. See Performance. For WebXR features that the engine doesn't cover, see Using WebXR Directly.
In This Section
- Getting Started - Setting up XR on each surface, and a first VR scene.
- Sessions - Session types, starting and ending sessions, features, reference spaces and the camera rig.
- Input Sources - Controllers, hands, screen taps and look and pinch, with their rays and actions.
- Controllers - Grip poses, controller models, buttons, thumbsticks and haptics.
- Hand Tracking - The joints of the user's hands, and gestures.
- Pointing and Grabbing - Picking, grabbing and throwing objects, and grabbing the scene.
- Locomotion - Teleporting, moving and turning the user.
- AR - Hit testing, anchors, plane and mesh detection, depth sensing and more.
- Performance - Resolution, frame rate, foveation and keeping each frame on time.
- Testing and Debugging - Emulating a headset in a desktop browser, and testing on devices.
- Platforms - Devices and browsers, and the features of each.
- Troubleshooting - Common problems and their causes.
See Also
- WebXR Hello World and the other WebXR tutorials - Tutorials that build XR applications in the Editor
- UI in XR - Panels, pointing and menus in immersive sessions
- XR Support and XR in PlayCanvas React - XR on the Web Components and React surfaces
- XR examples - The engine's XR examples