LibrarySetting up a basic XR Scene

Setting up a basic XR Scene

Learn about Setting up a basic XR Scene as part of AR/VR Development with Unity XR

Setting Up a Basic XR Scene in Unity

This module will guide you through the essential steps to set up a foundational XR (Extended Reality) scene in Unity, leveraging the XR Interaction Toolkit. This is a crucial first step for anyone looking to develop AR or VR experiences.

Prerequisites

Before you begin, ensure you have the following installed:

  • Unity Hub and a compatible Unity Editor version: Unity 2020.3 LTS or later is recommended.
  • XR Plugin Management: This package allows Unity to interface with various XR hardware.
  • XR Interaction Toolkit: This package provides a framework for building XR interactions.

Installing Necessary Packages

Unity's Package Manager is your central hub for managing project assets. We'll use it to install the required XR packages.

What Unity tool is used to install XR packages?

The Package Manager.

To install the packages:

  1. Open your Unity project.
  2. Navigate to <b>Window > Package Manager</b>.
  3. In the Package Manager window, ensure 'Unity Registry' is selected in the dropdown at the top left.
  4. Search for 'XR Plugin Management' and install it.
  5. Search for 'XR Interaction Toolkit' and install it.

Configuring XR Plugin Management

Once installed, you need to configure the XR Plugin Management to specify your target XR platform (e.g., Oculus, OpenXR, AR Foundation).

  1. Go to <b>Edit > Project Settings</b>.
  2. In the Project Settings window, select <b>XR Plug-in Management</b> from the left-hand menu.
  3. Under the 'PC Standalone' tab (or your target platform), check the box for your desired XR provider (e.g., OpenXR, Oculus).

OpenXR is a royalty-free, open standard that provides a unified API for XR devices, making your project more portable across different hardware.

Setting Up the XR Origin

The XR Origin is the core component that represents the player's presence in the XR environment. It typically includes the camera, controllers, and tracking space.

  1. In your Unity scene, delete the default 'Main Camera'.
  2. Right-click in the Hierarchy window and select <b>XR > XR Origin (VR)</b> or <b>XR Origin (AR)</b> depending on your project type.
  3. This will add an 'XR Origin' GameObject to your scene, which contains the necessary components for tracking and rendering.
What GameObject represents the player's presence in an XR scene?

The XR Origin.

Adding Basic Interactivity

The XR Interaction Toolkit provides pre-built components for common interactions like locomotion and object manipulation. For a basic setup, we can add a simple locomotion system.

  1. Select the 'XR Origin' GameObject in the Hierarchy.
  2. In the Inspector, click 'Add Component'.
  3. Search for and add 'Locomotion System'.
  4. Select the 'LeftHand Controller' and 'RightHand Controller' GameObjects under the XR Origin.
  5. Add a 'XR Controller (Action-based)' component to each hand controller.
  6. You'll need to set up Input Actions for movement and interaction. For a basic setup, you can use the default XR Interaction Toolkit input actions.

The XR Origin GameObject is a hierarchical structure. At its root is the XR Origin itself, which defines the tracking space. Within this, you'll find the Camera Offset, which adjusts the camera's position relative to the origin (e.g., for standing or seated experiences). Finally, the Camera component is attached to a GameObject within the Camera Offset, representing the player's viewpoint. Hand controllers are typically children of the XR Origin, allowing their position and rotation to be tracked independently.

📚

Text-based content

Library pages focus on text content

Testing Your Scene

With your XR Origin set up and basic configurations in place, you can now test your scene. Connect your XR device and press the Play button in Unity. You should be able to see your scene through your headset and potentially interact with it using your controllers.

What is the final step to verify your XR scene setup?

Testing the scene by playing it in Unity with an XR device connected.

Learning Resources

Unity XR Interaction Toolkit Documentation(documentation)

The official Unity documentation for the XR Interaction Toolkit, covering installation, setup, and core concepts.

Setting Up XR in Unity - Unity Learn(tutorial)

A comprehensive learning path from Unity Learn that covers XR development fundamentals, including project setup.

XR Plugin Management - Unity Documentation(documentation)

Detailed guide on how to use Unity's XR Plugin Management system to configure XR providers.

Introduction to XR Interaction Toolkit - Unity Blog(blog)

An introductory blog post from Unity explaining the benefits and features of the XR Interaction Toolkit.

Unity XR Interaction Toolkit: Getting Started(video)

A beginner-friendly video tutorial demonstrating the initial setup of the XR Interaction Toolkit in Unity.

OpenXR - Unity Documentation(documentation)

Information on configuring and using the OpenXR plugin for cross-platform XR development in Unity.

XR Origin in Unity Explained(video)

A video tutorial specifically explaining the XR Origin GameObject and its components in Unity.

Unity XR Interaction Toolkit: Locomotion(documentation)

Official documentation on setting up various locomotion systems using the XR Interaction Toolkit.

What is Extended Reality (XR)?(wikipedia)

A Wikipedia article providing a broad overview of Extended Reality, including AR, VR, and MR.

Unity Input System for XR(documentation)

Unity's official documentation for the new Input System, essential for mapping controller inputs in XR.