Setup for VR projects & Open XR Support
This blog will help you get started with creating VR games using XR Interaction Toolkit in Unity. Also, helpw you setup Unity for using it with HTC Vive or any other OpenXR supported devices.
How to set up Unity for HTC Vive
The latest XR Manager Plugin does not come with OpenXR support. It has to be downloaded separately and installed, which is not that difficult.
The steps mentioned in step 1 and 2 of this post is derived from this YouTube tutorial. If you have the XRInteraction Toolkit and the XRController set up already, you can jump to section 3 which shows how HTC Vive can be used with the OpenXR plugin.
Step 1: Downloading XRInteraction package
This section explains the steps that are to be taken to downloading and import XR Interaction Toolkit into Unity.
Open Unity hub and create and a new Project, I am calling it "Hello VR". It's better to use the Universal Render Pipeline as the template as the graphics will look better on build when compared to 3D template, however you can choose 3D as well.
Unity will open with a default scene. You can either use the same scene or create a new scene to work with. To create a new scene, select the scene folder in the Project window, right-click on it,
Scene. Rename the scene and double click to open.
OpenXR and XR Interaction toolkit plugins are currently in preview state, which means that it is not a full release and therefore bugs can still be present. Furthermore, it is placed under 'Preview Packages' in the Package Manager. As of now, you have no other option but to use it. To view the preview packages, see the following steps:
Package Manager→ select the setting icon ⚙ →
Advanced Project Setting→ Check the box for "Enable Preview Packages" and select
I understand. It’s just a warning that it’s a preview package and not yet released so it could potentially have bugs.
To import the XR Interaction Toolkit, open package manager → select
Unity Registryfrom the drop-down → search for "XR Interaction Toolkit" or scroll down to find it.
- Select that package → Click on
See other versions→ select
1.0.0-pre.3and install it.
- After installing a window will pop up asking you to restart Unity, click on
- Select that package → Click on
After Unity restarts, navigate back to the XR Interaction Toolkit package in the package manager. Import
Default Input Actionand
XR Device Simulator
This concludes section 1. The next section is to set-up the XR rig and other components to enable us to use VR controllers.
Section 2: Setting up XR Rig
This section explains how the XR rig can be set up with the default key bindings. We have the option to manually assign it but that is a tedious and time-consuming process. So to begin with, it's recommended to use the default setting and later on you can customize the controls.
- In the Project window navigate to Samples → XR Interaction Toolkit → 1.0.0-pre.3 → Default Input Actions. Here select "XRI Default Left Controller" and from the inspector window click on Add to ActionBasedController default. Next, select "XRI Default Right Controller" and perform the same action once again.
- To make sure we get the default values as preset, select
Preset manager, under ActionBasedController type in the filter "Left" and "Right" for the respective presets.
- Delete the Main camera from the Hierarchy. Right-click on the hierarchy window →
Room Scale XR Rig (Action-Based). If you look at the child of the XR Rig you will notice that, both the Left and the Right controllers come with default values now.
- Select the XR Rig and add the component Input Action Manager, change the Action Assets list size to 1. In the project window navigate to Samples → XR Interaction Toolkit → 1.0.0-pre.3 → Default Input Actions. Select the "XRI Default Input Actions", drag and drop it in the Input Action Manager component.
- Add a 3D plane to mark the play area, it’s not necessary but its helps with visualization.
This completes the basic setup for developing VR projects. The next section shows the setup of OpenXR
Section 3. Setting up OpenXR Plug-in
The OpenXR plugin was released recently for Unity version 2020. Earlier, developers had to use the older Unity versions for it to be compatible with HTC Vive.
- To download and install OpenXR plugin, Click on
- Navigate to
XR Plug-in Managementand check the box ☑ for OpenXR.
- In the same window, click on features under OpenXR and check the box ☑ for HTC Vive Controller Profile.
Note: If you scroll down in the list of features, there is an option of Valve index. I haven't tested that, but if you are an Index user do check that out. It should definitely work.
- The last step is to fix a few setup errors. Select the
XR Plug-in Management→ Click on the exclamation mark → Select the option
With that done, HTC Vive and its controllers can now be used to develop the project.
The Open XR plugin is stable even though it's in the preview version. I didn't face any bugs so far. I'm not sure if this plugin supports other PC VRs, that's something you will have to find out by yourself.
🎉 With that, we have finished setting up Unity to create our VR projects.
Thanks for reading this blog post. 🧡 If you are interested in creating your own AR and VR apps, you can learn more about it here on immersive insiders. Also, if you have any questions, don't hesitate to reach out! We're always happy to help.