Enabling VR in Unity with the Oculus Rift

Published in VR

Oculus and Unity make it simple to get started with VR. Here we will connect a Unity scene to an Oculus Rift headset and touch controllers using an Oculus SDK. It is assumed that Unity3D and the Oculus desktop app are both installed. I am using Unity version 2018.3.7.


First, get Oculus Integration and add it to your project. Oculus Integration is an SDK library provided by Oculus and is available for free in the Unity Asset store.

Then, in the Oculus desktop app head over to settings and under General, turn on Unknown Sources. This will allow Unity to connect to the Rift.

Basic Setup

Open or start a new 3D project. Then in Unity the first thing to do is to enable VR. Go to Edit > Project Settings > Player > XR Settings and check Virtual Reality Supported. Confirm that Oculus is listed as a VR device.

Then, in your scene delete the main camera since it is not needed as the image will be sent to the headset. Drag in an OVRPlayerController prefab item to your hierarchy.

Adjust the position as needed for the OVRPlayerController item so that the capsule is resting on any ground surface.

Simply doing these two things will allow the headset to work and allow movement via the controller joysticks. Pressing the left trigger button speeds up movement. Click the Play button to test.

Hand Avatars

To add hand avatars, drag on to the top level the CustomHandLeft and CustomHandRight prefabs. 

Then set the field for the Parent Transform to the TrackingSpace of the OVRPlayerController.

Hands should now be visible in the game.

Grabbing Objects

Grabbing objects is similarly simple using the included scripts in the Oculus Integration package. Grabbing functionality is included by default with the CustomHandLeft and CustomHandRight prefabs. This is confirmed by finding in the inspector pane an OVR Grabber script:

To make an object grabbable, add an OVR Grabbable script and a Rigidbody component to it. Turn off Use Gravity for the rigidbody if needed.