Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 4

Setting Up Your First VR Scene with XR Origin

Recommended resources

Welcome back. In our last lesson, you successfully installed and configured the XR Interaction Toolkit (XRI), equipping your project with the high-level framework needed to build VR interactions. You imported the necessary starter assets and, crucially, set up the default controller presets—a step that will begin to pay off today.

Now that the foundational packages are in place, it's time to bring a "player" into our virtual world. This lesson will guide you through setting up a basic VR scene by introducing the single most important object for a VR user: the XR Origin. Think of the XR Origin as the virtual embodiment of the user, a container for their viewpoint (the camera) and their hands (the controllers). By the end of this lesson, you will have a valid VR-ready scene with a player rig, a ground plane, and an object to look at, setting the stage for testing and interaction.

1. Preparing the Scene

Every new Unity scene starts with a couple of default objects: a Main Camera and a Directional Light. The XR Origin prefab we're about to add includes its own camera, which is specifically configured for VR. To avoid conflicts where Unity doesn't know which camera to use, our first step is always to delete the default one.

  1. In the Hierarchy window, you will see a SampleScene with a Main Camera and a Directional Light.
  2. Right-click on the Main Camera and select Delete.
  3. To give us something to stand on and look at, let's add a floor and a simple object.
    • Right-click in an empty area of the Hierarchy window, go to 3D Object, and select Plane. This will serve as our ground.
    • Right-click again, go to 3D Object, and select Cube. By default, it will be placed at the world origin (0, 0, 0), intersecting the plane. Select the Cube in the Hierarchy, and in the Inspector window, change its Transform properties to Position(X: 0, Y: 1, Z: 2) so it floats in front of where we will be standing.

Your scene is now a blank stage, ready for the main actor.


2. Adding the XR Origin (VR) Prefab

The XR Origin is a prefab, which in Unity is a pre-configured, reusable GameObject. It bundles together the camera, controller tracking objects, and necessary components into a single, easy-to-use package. This component-based, reusable design is a core principle of Unity development, much like how you would use reusable LWC components to build a complex Salesforce UI.

Let's add it to our scene.

  1. Right-click in an empty area of the Hierarchy window.
  2. Navigate to XR > XR Origin (VR).
The XR Origin (VR) prefab is added to the scene from the `XR` section of the GameObject creation menu.

You will see two new objects appear in your Hierarchy: XR Interaction Manager and XR Origin (VR).

  • The XR Interaction Manager is a singleton that orchestrates all interactions within the scene. It's the central hub that processes input and manages how interactors (like your hands) affect interactables (like objects you can grab).
  • The XR Origin (VR) is the player rig itself.

Let's examine the structure of the XR Origin. If you expand it in the Hierarchy, you will see several child objects.

The XR Origin is a parent object containing the Camera Offset, which in turn holds the Main Camera and the Left and Right Controllers. This structure correctly maps physical user movement to the virtual world.

This hierarchy is designed to correctly translate the user's real-world movements into the virtual space:

  • XR Origin: The root of the player rig. Its position represents the center of the tracking space.
  • Camera Offset: This child object is used to adjust the camera's height relative to the tracking origin. For example, it allows the system to correctly position the camera at the user's eye level above the floor.
  • Main Camera: This is the user's viewpoint. It tracks the headset's position and rotation relative to the Camera Offset.
  • Left Hand Controller & Right Hand Controller: These objects will track the position and rotation of your physical VR controllers.

3. Configuring the XR Origin

With the XR Origin in the scene, there is one critical configuration we need to set: the Tracking Origin Mode. This setting tells the system how to interpret the tracking data from the headset.

Select the XR Origin (VR) GameObject in the Hierarchy to view its components in the Inspector. You will see an XR Origin component with a dropdown for Tracking Origin Mode.

  • Device: This mode sets the origin of the tracking space to the initial position of the headset. It's suitable for 3DOF (3 degrees of freedom) experiences or seated gameplay where the user's position doesn't change much.
  • Floor: This mode sets the origin of the tracking space to the floor of the user's physical playspace. The system then uses the headset's height above the floor to position the camera correctly. This is the standard for room-scale VR experiences (6DOF), which is what we are building.

Let's set this now.

XR Step-by-Step 2023! Meta Quest: Setting up your Meta Quest XR Project! Unity 2022 + Open XR + XR Interaction Toolkit – Lance Larsen – Microsoft MVP – Hololens / VR / AR

This guide from Lance Larsen provides a concise walkthrough of the scene setup. We will use it to correctly configure the tracking mode.

In the article, find the section titled "Setup New Scene." You've already added the Plane and Cube. Now, focus on the instructions that follow adding the XR Origin. Specifically, read the steps under the image that shows adding the XR Origin (VR), starting from this instruction, to set the Tracking Origin Mode to Floor.


4. Verifying the Controller Setup

In the previous lesson, you configured default presets for the left and right controllers. Now, you get to see the benefit of that work.

Select the Left Hand Controller GameObject (nested under XR Origin (VR) > Camera Offset). In the Inspector, look at the XR Controller (Action-based) component. You'll see that all the action reference fields (like Position Action, Select Action, etc.) are already filled in. The same is true for the Right Hand Controller.

Because you set up the presets, Unity automatically linked the correct input actions from the Starter Assets to these controllers when you added the XR Origin to the scene. This saves you from having to manually assign over a dozen references, reducing setup time and potential for error.

The following video provides a great visual summary of this entire process, from adding the rig to verifying the auto-populated actions.

How to Setup the XR Interaction Toolkit - 2023 Unity VR Basics

This video from Fist Full of Shrimp demonstrates the process of adding and configuring the XR Origin. It's a useful recap of what we've just done.

First, watch the segment from adding the rig to see the XR Origin being added and its hierarchy explored. Then, skip ahead and watch the part from connecting the inputs, which clearly explains both the problem of unassigned actions and how the preset manager we configured in the last lesson solves it automatically.

Your scene is now correctly configured with a VR player rig.


Conclusion

In this lesson, you transitioned from abstract project settings to building the tangible core of a VR experience. You created a minimal test environment, added the essential XR Origin prefab, and understood its hierarchical structure. Most importantly, you configured its tracking mode for a room-scale experience and saw how the groundwork you laid in the previous lesson streamlined the controller setup process.

Key Takeaways:

  • The XR Origin (VR) prefab is the representation of the user in the virtual scene, containing the camera and controller tracking objects.
  • The default Main Camera in a new scene must be deleted to avoid conflicts with the XR Origin's camera.
  • The hierarchy of the XR Origin (Origin > Camera Offset > Camera/Controllers) is crucial for correctly mapping real-world movement.
  • Setting the Tracking Origin Mode to Floor is the standard for room-scale VR applications.
  • Configuring presets in the Project Settings automates the assignment of input actions to the controllers, saving time and preventing errors.

You now have a player, a stage, and a prop. But how do you test it all without a physical headset? In our next lesson, you will learn how to configure and use the XR Device Simulator to control the camera and hands using your mouse and keyboard, allowing you to effectively test and develop your VR application directly within the Unity editor.