How To : Unity VR Basics 2023 – Setup (XR Interaciton Toolkit)

Unity 2022 LTS has been released and I’ve taken it as a sign to redo my VR Basics tutorials. The XR Interaction Toolkit is now at version 2.3.2 and when I did my basics tutorials, it was still at 2.0.0. 

There’s a ton of changes and things to explore, so let’s go back to basics and get things set up.

Installing Unity 2022 LTS

Installing Unity 2022 LTS may not sound like the latest version for Unity, but for development purposes it is. Unity releases their most recent and stable version of Unity roughly 6 months after a new year. The most recent version in 2022 was the 2021 LTS and now we have been blessed with the 2022 LTS midway through 2023.

To download, we’ll need to get Unity Hub and  download the version of Unity we want from there. You can find Unity Hub here.

Once downloaded, installed and opened, we’ll be greeted with this!

To install the correct editor version, do the following.

  • Select Installs
    • Select Install Editor
      • Select 2022.3.2f1 (Or the most recent version of 2022)
        • Select Android Build Support, OpenJDK, and Android SDK & NDK Tools
        • Select Continue
 

It’ll take some time, but once it’s finished, Unity 2022 LTS will be ready for use!

Creating a New Project

Let’s start a new project. 

  • Select New Project
    • Use Editor Version Dropdown at the top center of the window to select version 2022 LTS
    • Select 3D (URP) as the base template to build the project
    • Set project name to ‘VR Basics’
    • Create Project
We’re choosing the URP version because it’ll allow us to optimize our VR games. If you want more information about the URP, you should check out my video on it found here.

XR Plugin Management

In order to get VR working, we’re going to need to be able to take input from a wide range of different devices. In order to handle all the different plugins required to deploy to all these different devices, we’re going to need to install the XR Plugin Manager. 

  • Edit -> Project Settings -> XR Plug-in Managment
    • Install the XR Plug-in Manager
    • Under the PC Tab
      • Select Open XR (May cause editor to restart) 
    • Under the Android Tab
      • Select Open XR
    • Select OpenXR (under XR Plug-in Management)
    • Under the PC Tab
      • Add Interaction Profiles you’re deploying to (ie. Oculu, Vive, Index, ect) using the ‘+’ sign
    • Under the Android Tab
      • Add Interaction Profiles you’re deploying to (ie. Oculu, Vive, Index, ect) using the ‘+’ sign

Importing the XR Interaction Toolkit

Next, we’re going to need a framework so we can develop for VR. Frameworks and toolkits help provide a ton of functionality so we don’t have to build everything from the ground up. The one that I’m going to use for this tutorial series is the XR Interaction Toolkit. To install it, do the following.

  • Window -> Package Manager
    • Method 1
      • Use top left dropdown and select Unity Registry
      • Search for XR Interaction Toolkit (search is in top right)
    • Method 2
      • If the XR Interaction Toolkit doesn’t appear in the search, do the following
      • Use top right plus to ‘Install package form git URL ‘com.unity.xr.interaction.toolkit’
      • This will automatically install the package
It may ask if you’ve made a backup of your project and reset the editor. Just click ‘I have made a backup’ and reset.
 
We’re also going to want to add in some addition packages from the XR Interaction Toolkit.
  •  Select XR Interaction Toolkit
    • Samples
      •  Import Starter Assets 
 

With that, we can now start building out our testing environment!

Testing Environment and XR Rig

Let’s setup our testing environment. For this tutorial, we’ll keep it simple and just add a Plane for us to stand on.

  • Right click in Hierarchy -> 3D -> Plane

I like to add a material to my plane just so it isn’t a dull grey color, but it isn’t necassary. 

Next, we need to set up the XR Rig. This will be responsible for handling our camera, hands and well… Everything!!!!

  • Right click in Hierarchy  -> XR -> XR Origin VR
  • Expand out XR Origin
    •  Select LeftHand Controller
      • Remove Sorting Group, XR Interactor Line Visual, Line Renderer, XR Ray Interactor
    • Select RightHand Controller
      •  Remove Sorting Group, XR Interactor Line Visual, Line Renderer, XR Ray Interactor
You’ll notice that adding the XR Origin also generates the XR Interaction Manager. This will be responsible for all the interaction between ourselves (interactor) with objects (interactable). We’ll cover that in a different video, but I did want to point it out.
 
If we select one of our controllers, we’ll see that an entire list of Input Actions are missing. In order to fill these, we need to use an Input Action map. Luckily, the XR Interaction Toolkit Samples that we downloaded already provided one! Now we just need to attach it to our controllers.
  • Select LeftHand Controller
    • In the top right of the XR Controller component, select the middle icon
      •  Select XRI Default Left Controller
  • Repeat the above steps, but for the Right Controller
With that, we should now have our Input Actions set.

As a bonus, we can also have these automatically apply when we generate a XR Origin

  • Assets -> Samples -> XR Interaction Toolkit -> 2.3.2 -> Starter Assets
    • Select XRI Default Left Controller
      •  At the top of the Inspecter, Select Add to ActionBasedController default
    • Repeat for the XRI Default Right Controller
 

Last, we need to connect it using the Preset Manager.

  • Edit -> Project Settings -> Preset Manager
    •     Enter ‘left’ in the empty slot next to XRI Default Left Controller
    •     Enter ‘right’ in the empty slot next to XRI Default Right Controller

Now when we create a XR Origin, it’ll automagically fill out our Input Actions for each controller.

Input Action Manager

The last piece to the XR Origin puzzle is the Input Action Manager. As the name implies, it’s responsible for managing all our Input Actions from our controllers.

  • Right click in Hierarchy -> Create Empty – name it ‘Input Action Manager’
  • Select Input Action Manager
    • Add Component – Input Action Manager
      • Select Plus Sign under Action Assets
      • Add the XRI Default Input Actions into the empty slot

With the Input Action Manager set, we can now boot up the Scene with our headset connected and see if it’s working.

Conclusion

For tracking purposes, I’ve attached two small spheres on the Left and Right Controllers of the XR Origin. I suggest doing the same to make sure the controller tracking is working.

With that, we now have set the stage for being able to develop VR games!

Next week I’ll be covering the Input Mapping and Hand Animations so we don’t need to settle for using spheres as hands.