Create your reality

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.

  1. 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.

    URP template

  2. 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, CreateScene. Rename the scene and double click to open.

    Creating new scene

  3. 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:
    Click on WindowsPackage 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.

    Package manager

  4. To import the XR Interaction Toolkit, open package manager → select Unity Registry from 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.3 and install it.

      XRInteraction toolkit

    • After installing a window will pop up asking you to restart Unity, click on Yes to continue.

      XRInteraction toolkit

  5. After Unity restarts, navigate back to the XR Interaction Toolkit package in the package manager. Import Default Input Action and XR Device Simulator

    Import samples

    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.

  1. 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.

    Default controller

  2. To make sure we get the default values as preset, select FileBuild SettingsPlayer settingPreset manager, under ActionBasedController type in the filter "Left" and "Right" for the respective presets.

    Preset Manager

  3. Delete the Main camera from the Hierarchy. Right-click on the hierarchy window → XR → select 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.

    XR Rig

  4. 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.

    XRI Default Input Actions

  5. Add a 3D plane to mark the play area, it’s not necessary but its helps with visualization.

    XRI Default Input Actions

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.

  1. To download and install OpenXR plugin, Click on WindowsPackage ManagerInstall OpenXR plugin

    OpenXR plugin

  2. Navigate to FileBuild settingsPlayer settingsXR Plug-in Management and check the box ☑ for OpenXR.

    Enable plugin

  3. In the same window, click on features under OpenXR and check the box ☑ for HTC Vive Controller Profile.

    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.

    Index Controller Profile

  4. The last step is to fix a few setup errors. Select the XR Plug-in Management → Click on the exclamation mark → Select the option Fix All.

    XR Plug-in Management

With that done, HTC Vive and its controllers can now be used to develop the project.

Conclusion

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.

_____________________

Thank you

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.

You’ve successfully subscribed to immersive insiders
Welcome back! You’ve successfully signed in.
Great! You’ve successfully signed up.
Your link has expired
Success! Check your email for magic link to sign-in.