This document explains how to quickly develop XR interactions in both the editor and ProCode environments.
The workflow for developing XR interactions in the editor is as follows:
Click Create Project on the Home Page, then select WebXR
as the physics backend in Project Settings.
Add an XR node in the Hierarchy Panel.
Adding an XR node automatically creates and selects
origin
andcamera
. Therefore, no otherCamera
components should exist in the scene unless intentionally added.
Multiple XR nodes can be added to a scene, but only one XR node will be active at any given time.
If you've followed the XR Debugging Guide and installed Chrome with the Immersive Web Emulator extension, you can preview directly now.
To achieve immersive mixed reality effects, additional capabilities can be added to XR interactions.
Add the XR Anchor Manager
component to any active entity to enable anchor tracking in XR.
Property | Description |
---|---|
Anchor List | List of anchors to track, defined by Position and RotationQuaternion |
Prefab | If set, this prefab will be instantiated and attached to the tracked anchor |
Add the XR Image Manager
component to any active entity to enable image tracking in XR.
Property | Description |
---|---|
Image List | List of reference images for tracking |
Prefab | If set, this prefab will be instantiated when the image is tracked |
To upload reference images:
Right-click in the Asset Panel → Upload → XRReferenceImage → Select the target image.
Property | Description |
---|---|
Name | Unique identifier for the tracked image |
Prefab | If set, this prefab will be instantiated when the image is tracked |
Image tracking cannot be debugged in the editor. Mobile preview and debugging are required after export.
Add the XR Plane Manager
component to any active entity to enable plane tracking in XR.
Property | Description |
---|---|
Detection Mode | Plane detection mode (None , Horizontal , Vertical , Everything ) |
Prefab | If set, this prefab will be instantiated when a plane is detected |
Note that WebXR
requires entering the XR context via a button click on the page. For XR projects, the editor automatically adds a button during preview. After export, developers must manually implement this:
// XR Manager
const xrManager = engine.xrManager;
// Target XR session mode
const xrMode = XRSessionMode.AR;
engine.xrManager.sessionManager.isSupportedMode(xrMode).then(
() => {
// Enter XR session on button click
htmlButton.onclick = () => {
xrManager.enterXR(xrMode);
};
},
(error) => {
// Mode not supported
console.error(error);
}
);