Project 2: Barrel Bouncer VR Edition

Part 1: Setting Up Your Project for VR

In this section, you’ll be applying some general project-wide settings that will optimize the performance for mobile VR. Then, you will install the XR development tools that you will use to build your app and do some basic set up in your scene to get it to work with the Oculus Quest headset and controllers.

General Project Settings

Build Settings

First, open up your Build Settings and modify the following:

Player Settings

Next, go in to your Player Settings and modify the following:

Quality Settings

So far, you’ve been opening up your Player Settings by clicking on the button in your Build Settings. However, the Player Settings are a small part of a larger set of settings for your project called Project Settings. The Project Settings window can also be launched by going to your menu bar and clicking on Edit -> Project Settings. Each type of project settings can be found on the tabs along the left fourth of the window.

One type of of project settings is the Quality Settings, which we will be modifying in this section. The first quality settings we will have to change are the Quality Levels. Since we are only building to the Android platform, we only care about the levels in the Android column. Make the Medium level the default level for Android and unselect all other levels so that they won’t be used. The default level for each platform is indicated by the green box. Below is a screenshot of what the level settings should look like.

Image showing quality level settings for Android

Next click on the Medium level so that you can modify the quality settings for that level to the values listed below:

Graphics Settings

The Graphic Settings are another type of project settings that you will have to modify to optimize it for performance on mobile VR systems.

Go onto the Tier Settings, uncheck the Use Defaults option for all tiers, and apply the following settings for each tier:

Downloading the XR Plugins and SDKs

There are two main tools we will need to obtain to get this project to work with VR: the Oculus XR Plugin, which is installed via Unity’s XR Management system, and the Oculus Integration SDK, which is installed via the Asset Store.

XR Management and the Oculus XR Plugin

As mentioned above, Unity has a new XR plug-in architecture that you should use to install and load the plugins for the XR platforms you would like your application to support. Below are the steps to install and set up the Oculus XR Plugin:

  1. In the same Project Settings window that you used above, click on the XR Plugin Management tab and then click on the Install XR Plugin Management button.
  2. Once this has completed, install the Oculus XR Plugin.
  3. Add the Oculus Loader to the list of Plugin Providers.
  4. Click on the Input Helpers subtab of the Project Settings and then click on the Install Legacy Input Helpers Package button.
  5. Click on the Oculus subtab of the Project Settings and then create a new serialized instance of the settings data.
  6. Change the Stereo Rendering Mode to Multiview. In Unity, each of the eyes of a VR headset is considered as its own separate camera/display, which can cause redundant computational and graphical workloads and thus significantly reduce performance. The Single Pass Stereo rendering mode provides some optimizations for a VR setup so that both cameras can share some computations and the same GameObjects are rendered onto both displays before iterating on to the next GameObject. Multiview is built on the same infrastructure as Single-Pass Instancing, but relies on the mobile graphics driver’s implementation of certain optimizations rather than Unity’s. To learn more about Single Pass Stereo rendering, check out this page on the Unity documentation.

GIF showing installation and setup of Oculus XR Plugin

The Oculus Integration

The Oculus Integration is a 3rd-party vendor-specific SDK provided by Oculus and as such can be found on the Asset Store. Once you find the Oculus Integration, download and import it into your project. Note that this step could take 15-30 minutes to complete, so it is advisable to work on something else while this finishes in the background. If you get popups saying that there are newer versions of plugins available, go ahead and select the option to upgrade them.

NOTE: The Oculus Integration defines its own Player Controller script, which can conflict with the script you defined and thus cause errors. As such, you should rename your script in order to avoid these errors, both by renaming the file itself from the project window and by changing the class name from within the file contents itself.

The Oculus Integration also includes many example scenes that showcase how to implement various VR features and setups using the Oculus Integration’s components and prefabs. These example scenes constitute its “Sample Framework”. Scenes that are part of the Sample Framework can be found in the following folder: Assets -> Oculus -> SampleFramework -> Usage. They may be a useful reference to you as you work on this project. The documentation that explains how each of the scenes work can be found at this link.

Basic Scene Setup

Headset Tracking

First, you should delete your Player GameObject from your scene and also make sure there are no other Cameras in your scene. The Oculus Integration already contains two prefabs that can act as a Player GameObject: the OVRCameraRig and the OVRPlayerController. For this project, we will use the OVRCameraRig prefab as our player GameObject, which is located in Assets -> Oculus -> VR -> Prefabs. Go ahead and drag this prefab into your scene, make sure its position and rotation are set to (0, 0, 0), and set its tag to “Player”.

The OVRCameraRig GameObject contains a few important components. The OVR Camera Rig component automatically adjusts the player’s camera’s translational and rotational movement based on the motion of the headset. The OVR Manager component provides the main interface to the VR hardware. The OVR Headset Emulator is supposed to allow you to simulate headset rotations from within the Unity Editor on your computer, but it only works with Windows and it doesn’t seem to work with the latest Unity version anyway.

You will need to set two properties of the OVR Manager component:

Controller Tracking

The OVR Manager also keeps track of the controllers’ movements and then appropriately adjusts the LeftControllerAnchor and RightControllerAnchor GameObjects to stay in sync with these motions. As a result, any 3D model or GameObject that is a child of the LeftControllerAnchor GameObject will also have its position automatically adjusted by the left hand controller’s movements, since its transform is defined relative to its parent.

The LeftControllerAnchor is a child GameObject of the LeftHandAnchor GameObject, which is a a child GameObject of the TrackingSpace GameObject, which is a child GameObject of the OVRCameraRig GameObject. The RightControllerAnchor also has a similar hierarchy structure.

The Oculus Integration also provides an OVRControllerPrefab, which determines and displays a model of the correct type of controller in your scene based on the type of headset you’re using (i.e. Oculus Go controlller, Gear VR controller, Oculus Quest Touch controllers, etc.). The OVRControllerPrefab is also located in the following folder: Assets -> Oculus -> VR -> Prefabs. Go ahead and create two instances of the OVRControllerPrefab, one as a child GameObject of the LeftControllerAnchor and one as a child GameObject of the RightControllerAnchor. Then, on the OVR Controller Helper component, specify the Controller type as L Touch and R Touch, respectively.

Once you have completed the scene setup, your hierarchy should look like this:

Exploded heirarchy of OVRCameraRig

Closing Notes

By this point, you should technically be able to build your app, run it from the Oculus Quest, and be able to look around your scene and see your controllers. However, you can’t actually see any of your canvases, you can’t move across large distances in your environment, and you can’t interact with any of the objects in your scene! For the rest of this project, you’ll be working to restore these interactive functionalities for this VR experience.

Previous Section | Go Home | Next Section