Get started with the Android XR Interaction Framework for Unity

Applicable XR devices
This guidance helps you build experiences for these types of XR devices.
XR Headsets
Wired XR Glasses

The Android XR Interaction Framework (AXRIF) provides familiar, high-level, opinionated interactions for OpenXR applications on Android XR. AXRIF bridges the gap between system-level interactions and in-app interactions, offering an intuitive and cohesive way to handle user input.

Follow this guide to set up and get started using AXRIF with Unity.

Prerequisites

Before beginning, ensure your development environment meets the following requirements:

Set up and configure Unity

Before you can try out the sample scene, you need to set up and configure Unity for AXRIF. Follow the steps in the following sections to complete this process.

Import the AXRIF package

First, install the AXRIF package and its dependencies:

  1. Navigate to Window > Package Manager.
  2. Open the add menu in the Package Manager toolbar.
  3. In the options for adding packages, click + (plus).
  4. From the drop-down menu, select Install package from git URL.

    Import the AXRIF package using its git URL.

  5. Enter the following URL:

    https://github.com/android-xr/android-xr-interaction-framework-unity-package.git

  6. Click Install.

    The AXRIF package details in Unity's Package Manager.

Check the XR Interaction Toolkit version

The AXRIF package works alongside the Unity XR Interaction Toolkit (XRIT) and doesn't replace it. Because the AXRIF package defines a dependency to XRIT, Unity should have installed XRIT when you installed the AXRIF package in the previous steps. However, you should check that version 3.3.1 or higher is installed by navigating to Window > Package Manager > Unity Registry > XR Interaction Toolkit in the Unity Editor.

Figure 1. Check the installed version of the XR Interaction Toolkit in the Unity Editor.

Select the Android XR build profile

Select the Android XR build profile to enable appropriate OpenXR Extensions and build settings for Android XR:

  1. Navigate to File > Build Profiles.
  2. Click Android XR, and then click Switch Platform.

    Select the Android XR build profile in Unity's settings.

Configure OpenXR settings

Configure Unity's OpenXR settings so Unity can access the necessary OpenXR data:

  1. Navigate to Edit > Project Settings > XR Plug-in Management > OpenXR.
  2. In the Android tab, click + (plus) for the Enabled Interaction Profiles section.
  3. Add any of the following profiles, depending on your app's needs:

    • Eye Gaze Interaction Profile
    • Hand Interaction Profile
    • Oculus Touch Controller Profile
    • Android XR Mouse Interaction Profile
  4. In the features list in XR Plug-in Management > OpenXR, enable the following features:

    • Android XR (Extensions): Passthrough Composition Layer
    • Android XR (Extensions): Session Management
    • Android XR Support
    • Android XR: AR Camera
    • Android XR: AR Session
    • Android XR: AR Hand Mesh Data
    • Composition Layers Support
    • Hand Tracking Subsystem

Perform project validation

Perform project validation to fix any OpenXR errors in your project's configuration:

  1. Navigate to Edit > Project Settings > XR Plug-in Management > Project Validation.
  2. Fix any outstanding alerts or warnings to ensure runtime errors don't affect compilation.

    Resolve any outstanding OpenXR issues by performing project validation.

Use the sample scene

Now that you've finished the preliminary setup and configuration, you can use the AXRIF sample scene. Follow the steps in the following sections to get the sample scene and try it out.

Import XRIT sample packages and the AXRIF sample

The AXRIF sample scene depends on Unity's XR Interaction Toolkit (XRIT) Starter Assets and Hands Interaction Demo sample packages.

Import XRIT sample packages

Import the XRIT sample packages that the AXRIF sample depends on:

  1. Navigate to Window > Package Manager.
  2. Select XR Interaction Toolkit from the package list.
  3. In the Samples tab, click Import next to both Starter Assets and Hands Interaction Demo.

    Import the required XRIT sample packages before you import the AXRIF sample package.

Import the AXRIF sample

Import the AXRIF sample to get the sample scene:

  1. Navigate to Window > Package Manager.
  2. Select Android XR Interaction Framework from the package list.
  3. In the Samples tab, click Import next to Axrif Sample.

    Import the AXRIF sample in Unity's package manager.

Open the Scene

After you've imported the required sample packages, you can open the scene:

  1. Navigate to Assets > Samples > Android XR Interaction Framework > [AXRIF Version Number] > Axrif Sample.
  2. Open AxrifDemoScene.

    Import the AXRIF sample package in Unity's package manager.

Explore the prefabs

The scene comes pre-configured using modular prefabs located under Packages > Android XR Interaction Framework > Prefabs.

Interactor prefabs

The Axrif Interactor prefabs drive Unity XRIT interactor mechanics using the corresponding input modalities from the following list:

  • Hand/Controller Ray:
    • Axrif Left Interactor - Uses left hand raycast or controller.
    • Axrif Right Interactor - Uses right hand raycast or controller.
  • Gaze Pinch:
    • Axrif Left GazePinch Interactor - Uses eye gaze and left-hand motion when pinching.
    • Axrif Right GazePinch Interactor - Uses eye gaze and right-hand motion when pinching.
    • Axrif Gaze Interactor - Uses eye gaze to point only.
  • Hand Poke:
    • Axrif Left Poke Interactor - Uses left index finger when touching interactables.
    • Axrif Right Poke Interactor - Uses right index finger when touching interactables.
  • Mouse:
    • Axrif Mouse Interactor - Uses Android XR spatial mouse.

Axrif Interaction Manager and Origin prefabs

  • Axrif Interaction Manager: This prefab is the central hub for AXRIF in the scene. The prefab houses the Axrif Interaction Manager component, which is designed to work in conjunction with the XRIT XR Interaction Manager. This prefab is responsible for:

    • Initializing and managing the core AXRIF subsystems at runtime.
    • Processing and routing input data from OpenXR using the Interaction Framework Input Adapter.
    • Observing UI and collider states using the Interaction Framework Scene Integrator.
  • Axrif XR Origin: Serves as the main character and camera driver and manages hand-mesh visualizers.

Configure input actions

To bridge the OpenXR runtime data with Unity's Input Actions, register project-wide map bindings:

  1. Navigate to Packages > Android XR Interaction Framework > InputActions.
  2. Locate AndroidXRInteractionFramework Input Actions.
  3. Click Assign as the Project-wide Input Actions.

    Configure input actions for Unity to bridge runtime data with Unity's Input Actions.

Modify interactions

Using the Axrif Interaction Manager prefab, you can enable or disable different input modalities. AXRIF supports the following input modalities:

  • Controller Raycasting
  • Pinch and Gaze
  • Hand Raycasting
  • Direct Hand
  • Mouse Interactions.

You can configure input modalities directly inside the Inspector in the Configurations section of the Interaction Framework Manager component.

Figure 2. Configure input modalities inside the Inspector.

Build the sample

When you want to build the sample, click Build or Build and Run in the Unity Editor.