This guide is not version specific, but for reference sake, was made with Unity 2020.3.7f1
. An additional tip is that the project you create for VR is preferably using URP (Universal Render Pipeline), to make sure performance is maximized (also see VR lighting settings).
Note: There are other ways to set up a VR project. Each has their own advantage. The main advantage of this one is that it is non-specific to the VR device you are using. Alternatively, if you want to use SteamVR based devices only, you may want to use the SteamVR Unity plugin, and for example if using Oculus (/Meta these days) devices only you may want to look at the Oculus Integration SDK.
also see: official documentation: Configuring your Unity Project for XR
- First, Open Steam and Start SteamVR.
- Add OpenXR plugin - Window ->
Package Manager
- (In the top of the window) click Packages:… and make sure its set to Unity registry (so that we’re looking for packages inside of the Unity registry)
- Search for OpenXR Plugin, click it in the list, and click install (for reference: we’re installing v1.1.1).
- Side note: from here you can also import some samples (click the dropdown arrow on Samples)
- Other side note: This will also install some dependency packages (like XR Plugin Management)
- You will (probably) get an error message about the Input system: ”This project is using the new input system package but the native platform backends for the new input system are not enabled in the player settings.This means that no input from native devices will come through. Do you want to enable the backends? Doing so will “RESTART” the editor and will “DISABLE” the old UnityEngine.Input APIs.” Click yes, OR (in case you rely on the old input system in some way) Click “No”, then in player settings (Edit > Project Settings > Player) scroll down and set “Active Input Handling” select “Both”.
- Add XR Interaction Toolkit
- Again, go to
Package Manager
, search for XR Interaction Toolkit, and install it.
- XR Settings
- Now we need to set some
Project Settings
to enable & configure all our XR stuff.
- Go to Edit –> Project Settings and find the XR Plug-in Management
- Enable the OpenXR Plug-in Provider.
- Click OpenXR (under XR Plug-in Management), and make sure you add an Interaction Profile, that is relevant to the device you are using (for HTC Vive, user HTC Vive controller profile).
- That’s it! Now we can make some VR magic happen.
To set up VR in the project:
- we first need to make sure we have a VR Rig in our scene. In your scene `Hierarchy` click *Right Mouse Button --> XR --> XR Origin*.
- This will spawn an XR Rig (set its transform to about where you want the player to spawn), along with an XR Interaction Manager game object (and remove any other main camera that is already in the scene).
- To be able to view the environment in VR, Now just run the scene (make sure that SteamVR is already running, this prevents some stupid errors) and voila you are viewing the scene in VR.
- From here you can do all kinds of things to extend the VR functionality, which won’t be covered in this guide.
For more information on the XR Interaction Manager package, see its official documentation.