Building for Oculus Rift
This section describes how to set up and build your VR project on an Oculus Rift desktop VR device. Using a Rift requires the Oculus Windows app to be running, and in Unity, you'll build with the Oculus SDK. (Alternatively, you can build for OpenVR and run your Oculus in SteamVR, in which case, follow the instructions in the previous section instead).
Using the Oculus SDK is required if you plan to publish on the Oculus Store or use any of the many advanced Oculus Integration platform features, including avatars, in-app-purchases (IAP), achievements, and more. See https://developer.oculus.com/platform/ for a list of features that are part of the Oculus platform solutions.
Before getting started, be sure you have your Rift connected to a PC (or a Quest connected with an Oculus Link cable) and that you're able to see and interact within the Oculus Home environment.
Setting up for Oculus desktop
To target the Oculus desktop, use the following Build Settings:
- Configure your Unity Build Settings so that they target the Standalone platform, if they're not already (File | Build Settings... | PC, Mac & Linux Standalone | Switch Platform).
- Set Target Platform to Windows and Architecture to x86_64.
Now, if you haven't already, add the Oculus XR plugin using the following steps:
- OpenXR Plugin Management in Project Settings using Edit | Project Settings | XR Plug-in Management.
- In the Plug-in Providers list, check the Oculus checkbox.
- You'll now see the Oculusoption in the left tab menu. Select it.
- Optionally, setStereo Rendering ModetoSingle Pass Instancedfor better performance.
Notice that the Oculus SDK has several options. By default,Shared Depth Buffer and Dash Support are enabled. These allow the Oculus system software to render into the same view while your app is running, for example, for popup Dash menus. The Oculus plugin options are shown in the following screenshot:
If you press Play now, you should see the scene playing in your VR headset. At this point, it's also advised that you Build And Run the project to verify it will build correctly and run as expected on your VR device.
The SDK we've installed is sufficient for the projects in this book. However, Oculus provides a rich collection of optional tools in the Oculus Integration toolkit.
Installing the Oculus Integration toolkit
As an Oculus app, you have the option of using the Oculus Integration toolkit for Unity, which is built on top of the native XR SDK. Oculus maintains this plugin, which provides advanced rending, social platform, audio, avatars, lipsync, and more. For the projects in this book, we do not depend on having this toolkit installed, but from time to time, we may give additional tips on using it to enhance a project. To install the Oculus Integration toolkit from the Asset Store, follow these steps:
- In your web browser, go to https://assetstore.unity.com/packages/tools/integration/oculus-integration-82022.
- Click Open In Unity and Install it into your project.
- If prompted, also allow updates to the OVRPlugin for the Unity Editor and/or other assets.
- Since we're using the Universal Render Pipeline, you should convert the imported materials (Edit | Render Pipeline | Universal Render Pipeline | Upgrade Project Materials).
The package installs a lot of stuff under the Project Assets/Oculus/ folder. I encourage you to explore the various subfolders, open example scenes, and even read through the scripts. A good place to start is StartScene in the Oculus/SampleFramework/Usage/ folder, as shown in the following screenshot:
The Oculus package also installs helpful menu items on the Unity Editor menu bar's Oculus menu. We won't go into details here, and they are subject to change. We encourage you to explore the options and shortcuts they provide. For more information on the Oculus Integration toolkit for Unity, see https://developer.oculus.com/unity/:
In your own projects, you can choose to replace our XR Rig camera rig with the OVRCameraRig prefab provided in the Oculus Integration, which can be found in the Assets/Oculus/VR/Prefabs/ folder. It is used in their various example scenes.
If you do not need to set up an additional VR device, you can move on to the next chapter. Next, we will consider the Windows Immersive Mixed Reality setup.