Oculus Utilities For Unity 5.x Developer Guide: Version 0.1.3.0 Beta
Oculus Utilities For Unity 5.x Developer Guide: Version 0.1.3.0 Beta
2|Introduction|Unity
OCULUS VR, OCULUS, and RIFT are trademarks of Oculus VR, LLC. (C) Oculus VR, LLC. All rights reserved.
BLUETOOTH is a registered trademark of Bluetooth SIG, Inc. All other trademarks are the property of their
respective owners. Certain materials included in this publication are reprinted with the permission of the
copyright holder.
2||
Unity|Contents|3
Contents
Introduction.......................................................................................................... 5
Compatibility and Requirements....................................................................................................................... 5
Downloading Utilities for Unity......................................................................................................................... 7
Preparing for Development: PC SDK................................................................................................................7
Preparing for Development: Mobile SDK......................................................................................................... 8
Getting Started.................................................................................................... 9
Unity VR Support............................................................................................................................................... 9
Importing the Oculus Utilities Package.............................................................................................................9
Importing Sample Applications: Mobile SDK................................................................................................. 10
Migrating to Utilities from the Integration Package....................................................................................... 11
OVRInput............................................................................................................ 20
OVRInput Usage.............................................................................................................................................. 20
Touch Input Mapping......................................................................................................................................23
Xbox Input Handling....................................................................................................................................... 24
4|Contents|Unity
Unity|Introduction|5
Introduction
This guide describes developing Unity 3D games and applications for VR devices with the Oculus PC and
mobile SDKs.
The Utilities package is for use with Unity Professional and Personal editions versions 5.x. Projects using
Unity 4 should use our Unity 4.x Legacy Integration package instead. We strongly recommend developers
beginning new projects use Unity 5.1+ and our Utilities package. For more information on version compatibility,
see Compatibility and Requirements.
This guide covers:
Getting started
Downloading and installing the Utilities package
Contents of the Utilities package
Input Mapping
How to use the provided samples, assets, and sample applications
Configuring Unity VR projects for build to various targets
Building a simple VR Unity game (tutorial)
Most information in this guide applies to the use of the Utilities package with either the Oculus PC or Mobile
SDKs. Any exceptions are clearly indicated where they occur (e.g., the Moonlight folder in OVR contains assets
designed for mobile development).
When developing for both Rift and mobile platforms, keep in mind that the requirements for PC and mobile
VR applications differ substantially. If you would like to generate builds for both PC and mobile from a single
project, it is important to follow the more stringent mobile development best practices.
Unity First-Party VR Support
With Unity 4, developers used the Oculus Integration package to import Oculus VR camera and controller
prefabs. In Unity 5.1+, developers may substitute a stereoscopic VR camera with built-in orientation and
positional tracking for their main camera by selecting the Virtual Reality Supported check box in Player Settings.
Unlike the Legacy Integration, which was necessary for VR support in Unity 4, the Utilities package is an optional
supplement with useful material to support development.
See Unity VR Support for more information.
6|Introduction|Unity
Recommended
Release
Unity 5.1+
Unity 5.3.1p4
Unity 5.0
n/a
Unity 4
Unity 4.7.0f1
For more details on the relationship between past and present Unity versions, Oculus PC and Mobile SDKs, and
Oculus Unity Integration and Utilities packages, see Unity-SDK Version Compatibility.
Oculus Runtime (PC Only)
For PC SDKs 0.7 through 1.0, each SDK version only guarantees support for the current and previous runtime
version, e.g., PC SDK 0.7 is only guaranteed to work with runtime versions 0.6, 0.6.0.1, and 0.7.
Utilities and Legacy Integration versions do not depend on specific runtimes, and will run with reduced
functionality on older Unity Versions and PC runtimes.
Unity Version
Integration/Utilities Version
Compatible PC Runtime
Unity 4.7.0f1
5.3.1p4
Utilities 0.1.3.0
Unity|Introduction|7
A feature set comparison between Unity Professional and Personal editions may be found here: http://
unity3d.com/unity/licenses
Gamepad Controller
You may wish to have a compatible gamepad controller for use with the supplied demo applications, such
as the Xbox 360 controller for Windows, an HID-compliant game controller for Mac, or a Moga Pro or other
compatible controller for Gear VR.
8|Introduction|Unity
Never clone displays. When the Rift is cloned with another display, the application may not vsync properly.
This leads to visible tearing or judder (stuttering or vibrating motion).
Unity|Getting Started|9
Getting Started
This section describes steps taken to begin working in Unity.
Unity VR Support
Unity 5.1 and later offer first-party virtual reality support, toggled by the Virtual Reality Supported checkbox in
the Other Settings > Configuration tab of Player Settings.
When Unity virtual reality support is enabled, any camera with no render texture is automatically rendered in
stereo to your device, and positional and head tracking is automatically applied to your camera, overriding your
cameras transform.
When Unity applies head tracking to the VR camera, it applies it within the reference frame of the camera's
local pose when the application starts. If you are using OVRCameraRig, that reference frame is defined by the
TrackingSpace GameObject, which is the parent of the CenterEyeAnchor GameObject that has the Camera
component.
The Unity Game View preview does not apply lens distortion. The image corresponds to the left eye buffer and
uses simple pan-and-scan logic to correct the aspect ratio.
For detailed information and instructions for using Unitys VR support, see the Virtual Reality section of the Unity
Manual.
Note: Unitys VR support is not compatible with previous Oculus Unity Integrations; see The Oculus
Utilities Package and Unity for more information.
Content to Delete
Assets/Plugins
Oculus.*
OVR.*
Assets/Plugins/
Android/
*Oculus*
AndroidManifest.xml
*vrapi*
*vrlib*
10|Getting Started|Unity
Folder
Content to Delete
*vrplatlib*
Assets/Plugins/x86/
Oculus.*
OVR.*
Assets/Plugins/
x86_64/
Oculus.*
OVR.*
Unity|Getting Started|11
If you are already working in a Unity project, save your work before beginning.
To import the Utilities package into Unity, select Assets > Custom Package... and select
BlockSplosion.unitypackage to import the assets into your new project. Alternately, you can locate the
BlockSplosion.unitypackage file and double-click to launch, which will have the same effect.
Each sample application project includes a ProjectSettings folder which provides default settings for the VR
mobile application. Copy these files to your [Project]/Assets/ProjectSettings folder.
The import process may take a few minutes to complete.
12|Getting Started|Unity
project built with the legacy Unity integration, editor scripts will patch up old OVRCameraRig GameObjects and
enable PlayerSettings.virtualRealitySupported, so the project should work without further action.
Note: Don't forget to move any scripts, image effects, tags, or references from the left and right eye
anchors to the center eye anchor as noted above.
Contents
OVR
The contents of the OVR folder in OculusUtilities.unitypackage are uniquely named and should be safe to
import into an existing project.
The OVR directory contains the following subdirectories:
Editor
Contains scripts that add functionality to the Unity Editor, and enhance several C#
component scripts.
Materials
Contains materials that are used for graphical components within the Utilities package,
such as the main GUI display.
Meshes
Contains Meshes that are required by some OVR scripts, such as the TrackerBounds.
Moonlight
Contains classes designed for Gear VR development. It holds sub-folders with mobile
equivalents of all top-level folders (Editor, Materials, Prefabs, et cetera).
Prefabs
Contains the main Unity prefabs that are used to provide the VR support for a Unity
scene: OVRCameraRig and OVRPlayerController.
Scenes
Scripts
Contains the C# files that are used to tie the VR framework and Unity components
together. Many of these scripts work together within the various Prefabs.
Textures
Contains image assets that are required by some of the script components.
Note: We strongly recommend that developers not directly modify the included OVR scripts.
Plugins
The Plugins folder contains the OVRGamepad.dll, which enables scripts to communicate with the Xbox
gamepad on Windows (both 32 and 64-bit versions).
This folder also contains the plugin for Mac OS: OVRGamepad.bundle.
Prefabs
The current integration for adding VR support into Unity applications is based on two prefabs that may be
added into a scene:
OVRCameraRig
OVRPlayerController
To use, simply drag and drop one of the prefabs into your scene.
OVRCameraRig
OVRCameraRig replaces the regular Unity Camera within a scene. You can drag an OVRCameraRig into your
scene and you will be able to start viewing the scene with the Gear VR and Rift.
Note: Make sure to turn off any other Camera in the scene to ensure that OVRCameraRig is the only
one being used.
Figure 1: OVRCameraRig and OVRManager
OVRCameraRig contains one Unity camera, the pose of which is controlled by head tracking; two anchor
GameObjects for the left and right eyes; and one tracking space GameObject that allows you to fine-tune the
relationship between the head tracking reference frame and your world. The rig is meant to be attached to a
moving object, such as a character walking around, a car, a gun turret, et cetera. This replaces the conventional
Camera.
The following scripts (components) are attached to the OVRCameraRig prefab:
OVRCameraRig.cs
OVRManager.cs
OVRPlayerController
The OVRPlayerController is the easiest way to start navigating a virtual environment. It is basically an
OVRCameraRig prefab attached to a simple character controller. It includes a physics capsule, a movement
system, a simple menu system with stereo rendering of text fields, and a cross-hair component.
To use, drag the player controller into an environment and begin moving around using a gamepad, or a
keyboard and mouse.
Note: Make sure that collision detection is active in the environment.
Two scripts (components) are attached to the OVRPlayerController prefab:
OVRPlayerController.cs
OVRGamepadController.cs
Figure 2: OVRPlayerController
Unity Components
The following section gives a general overview of what each of the scripts within the Scripts folder does.
OVRCameraRig
OVRCameraRig is a component that controls stereo rendering and head tracking. It maintains three child
"anchor" Transforms at the poses of the left and right eyes, as well as a virtual "center" eye that is halfway
between them.
This component is the main interface between Unity and the cameras. This is attached to a prefab that makes it
easy to add comfortable VR support to a scene.
Important: All camera control should be done through this component. You should understand this script when
implementing your own camera control mechanism.
Mobile and PC Public Members
Updated Anchors
Allows clients to filter the poses set by tracking. Used to modify or ignore positional
tracking.
GameObject Structure
TrackingSpace
A GameObject that defines the reference frame used by tracking. You can move this
relative to the OVRCameraRig for use cases in which the rig needs to respond to IR
sensor input. For example, OVRPlayerController changes the position and rotation of
TrackingSpace to make the character controller follow the yaw of the current head pose.
OVRManager
OVRManager is the main interface to the VR hardware. It is a singleton that exposes the Oculus SDK to Unity,
and includes helper functions that use the stored Oculus variables to help configure camera behavior.
This component is added to the OVRCameraRig prefab. It can be part of any application object. However, it
should only be declared once, because there are public members that allow for changing certain values in the
Unity inspector.
OVRManager.cs contains the following public members:
Table 1: Mobile and PC Public Members
Monoscopic
If true, rendering will try to optimize for a single viewpoint rather than rendering once
for each eye. Not supported on all platforms.
Disables the IR sensor and causes head position to be inferred from the current rotation
using the head model. To fully ignore tracking or otherwise modify tracking behavior,
see OVRCameraRig.UpdatedAnchors above
This value defaults to True. When turned off, subsequent scene loads will not reset the
sensor. This will keep the sensor orientation the same from scene to scene, as well as
keep magnetometer settings intact.
Helper Classes
In addition to the above components, your scripts can always access the HMD state via static members of
OVRManager.
OVRDisplay
OVRTracker
Provides the pose, frustum, and tracking status of the infrared tracking camera.
Utilities
OVRPlayerController
OVRGamepadController
OVRGamepadController is an interface class to a gamepad controller. It is crossplatform and works on the Samsung EI-GP20 Gamepad for Android if you include
InputManager.asset in your project.
On Windows systems, the gamepad must be XInput-compliant. To use the Xbox
controller on a Mac, install the TattieBogle driver.
OVRGridCube
OVRGridCube is a helper class that shows a grid of cubes when activated. Its main
purpose is to be used as a way to know where the ideal center of location is for the
user's eye position. This is especially useful when positional tracking is activated. The
cubes will change color to red when positional data is available, and will remain blue if
position tracking is not available, or change back to blue if vision is lost.
OVRTrackerBounds
Warns players when the HMD moves outside the trackable range.
GameObject Structure
ForwardDirection
Room
Cubes
Detailed code for how to create judder-free crosshairs tied to the camera view.
StartupSample.cs
Example code for loading a minimal-scene on startup while loading the main scene in
the background.
TimeWarp30HzSample.cs
Example code for setting up TimeWarp to support 30Hz apps as well as toggling
Chromatic Aberration Correction and Monoscopic Rendering on and off.
HomeMenu.cs
HomeButton.cs
HomeBattery.cs
Example code for using the SDK Battery Level API and interactively modifying a visual
indicator.
MoviePlayerSample.cs
Example code and documentation for how to play an in-game video on a textured
quad using Android MediaPlayer (mobile) or Unity's native media rendering (PC). Note:
libOculusMediaSurface currently works with GLES2 only.
OVRChromaticAberration.csDrop-in component for toggling chromatic aberration correction on and off for Android.
OVRDebugGraph.cs
Drop-in component for toggling the TimeWarp debug graph on and off. Information
regarding the TimeWarp Debug Graph may be found in the TimeWarp technical note in
the Mobile SDK documentation.
OVRModeParms.cs
Example code for de-clocking your application to reduce power and thermal load as
well as how to query the current power level state.
OVRMonoscopic.cs
Drop-in component for toggling Monoscopic rendering on and off for Android.
OVRResetOrientation.cs
OVRWaitCursor.cs
OVRPlatformMenu.cs
Helper component for detecting Back Key long-press to bring-up the Universal Menu
and Back Key short-press to bring up the Confirm-Quit to Home Menu. Additionally
implements a Wait Timer for displaying Long Press Time. For more information on
interface guidelines and requirements, please review Interface Guidelines and Universal
Menu in the Mobile SDK documentation.
20|OVRInput|Unity
OVRInput
Note: OVRInput is now our supported API for PC and Mobile input handling. OVRInputControl and
OVRGamepadController are now deprecated and will be removed in a later version.
OVRInput exposes a unified input API for multiple controller types. It may be used to query virtual or raw
controller state, such as buttons, thumbsticks, triggers, and capacitive touch data. It currently supports the
Oculus Touch and Microsoft Xbox controllers on desktop platforms. Gamepads compatible with Samsung Gear
VR, such as the Samsung EI-GP20 and Moga Pro, must be Android compatible and support Bluetooth 3.0. For
more details on supported mobile gamepad features, see System and Hardware Requirements in our Mobile
SDK documentation.
When used with tracked controllers such as Oculus Touch, OVRInput also provides position and orientation
data through GetLocalControllerPosition() and GetLocalControllerRotation(), which return a
Vector3 and Quaternion, respectively.
Controller poses are returned by the Constellation tracking system and are predicted simultaneously with
the headset. These poses are reported in the same coordinate frame as the headset, relative to the initial
center eye pose, and may be used for rendering hands or objects in the 3D world. They are also reset by
OVRManager.display.RecenterPose(), similar to the head and eye poses.
OVRInput provides control of haptic vibration feedback on compatible controllers. For example,
SetControllerVibration() sets vibration frequency and amplitude.
For keyboard and mouse control, we recommend using the UnityEngine.Input scripting API (see Unitys Input
scripting reference for more information).
Mobile input bindings are now automatically added to InputManager.asset if they do not already exist. The
InputManager.asset file previously provided to populate input bindings for mobile was deprecated with
Utilities 0.1.3.0, and is currently included for legacy use with our deprecated OVRGamepadController and
OVRInputControl APIs.
For more information, see the OVRInput reference. For more information on Unitys input system and Input
Manager, documented here: http://docs.unity3d.com/Manual/Input.html and http://docs.unity3d.com/
ScriptReference/Input.html.
Note: The term Touch in OVRInput refers to actual Oculus Touch controllers.
OVRInput Usage
The primary usage of OVRInput is to access controller input state through Get(), GetDown(), and GetUp().
Get() queries the current state of a control.
GetDown() queries if a control was pressed this frame.
GetUp() queries if a control was released this frame.
Control Input Enumerations
There are multiple variations of Get() that provide access to different sets of controls. These sets of controls
are exposed through enumerations defined by OVRInput as follows:
Unity|OVRInput|21
Control
Enumerates
OVRInput.Button
OVRInput.Touch
OVRInput.NearTouch
OVRInput.Axis1D
OVRInput.Axis2D
22|OVRInput|Unity
// returns true if the primary button (typically A) was pressed this frame.
OVRInput.GetDown(OVRInput.Button.One);
// returns true if the X button was released this frame.
OVRInput.GetUp(OVRInput.RawButton.X);
// returns a Vector2 of the primary (typically the Left) thumbsticks current state.
// (X/Y range of -1.0f to 1.0f)
OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
// returns true if the primary thumbstick is currently pressed (clicked as a button)
OVRInput.Get(OVRInput.Button.PrimaryThumbstick);
// returns true if the primary thumbstick has been moved upwards more than halfway.
// (Up/Down/Left/Right - Interpret the thumbstick as a D-pad).
OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp);
// returns a float of the secondary (typically the Right) index finger triggers current state.
// (range of 0.0f to 1.0f)
OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger);
// returns a float of the left index finger triggers current state.
// (range of 0.0f to 1.0f)
OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger);
// returns true if the left index finger trigger has been pressed more than halfway.
// (Interpret the trigger as a button).
OVRInput.Get(OVRInput.RawButton.LIndexTrigger);
// returns true if the secondary gamepad button, typically B, is currently touched by the user.
OVRInput.Get(OVRInput.Touch.Two);
In addition to specifying a control, Get() also takes an optional controller parameter. The list of supported
controllers is defined by the OVRInput.Controller enumeration (for details, see the OVRInput reference).
Specifying a controller can be used if a particular control scheme is intended only for a certain controller type.
If no controller parameter is provided to Get(), the default is to use the Active controller, which corresponds
to the controller that most recently reported user input. For example, a user may use a pair of Oculus Touch
controllers, set them down, and pick up an Xbox controller, in which case the Active controller will switch to
the Xbox controller once the user provides input with it. The current Active controller can be queried with
OVRInput.GetActiveController() and a bitmask of all the connected Controllers can be queried with
OVRInput.GetConnectedControllers().
Example Usage:
// returns true if the Xbox controllers D-pad is pressed up.
OVRInput.Get(OVRInput.Button.DpadUp, OVRInput.Controller.Gamepad);
// returns a float of the Hand Triggers current state on the Left Oculus Touch controller.
OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.Touch);
// returns a float of the Hand Triggers current state on the Right Oculus Touch controller.
OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger, OVRInput.Controller.Touch);
Note that the Oculus Touch controllers may be specified either as the combined pair (with
OVRInput.Controller.Touch), or individually (with OVRInput.Controller.LTouch and RTouch). This
is significant because specifying LTouch or RTouch uses a different set of virtual input mappings that allow
more convenient development of hand-agnostic input code. See the virtual mapping diagrams in Touch Input
Mapping for an illustration.
Example Usage:
// returns a float of the Hand Triggers current state on the Left Oculus Touch controller.
OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch);
// returns a float of the Hand Triggers current state on the Right Oculus Touch controller.
OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.RTouch);
Unity|OVRInput|23
This can be taken a step further to allow the same code to be used for either hand by specifying the controller
in a variable that is set externally, such as on a public variable in the Unity Editor.
Example Usage:
// public variable that can be set to LTouch or RTouch in the Unity Inspector
public Controller controller;
// returns a float of the Hand Triggers current state on the Oculus Touch controller
// specified by the controller variable.
OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, controller);
// returns true if the primary button (A or X) is pressed on the Oculus Touch controller
// specified by the controller variable.
OVRInput.Get(OVRInput.Button.One, controller);
This is convenient since it avoids the common pattern of if/else checks for Left/Right hand input mappings.
24|OVRInput|Unity
Raw Mapping
The raw mapping directly exposes the Touch controllers. The layout of the Touch controllers closely matches
the layout of a typical gamepad split across the Left and Right hands.
Unity|OVRInput|25
Raw Mapping
The raw mapping directly exposes the Xbox controller.
To build the demo as a standalone full screen application, you will need to change a few project settings to
maximize the fidelity of the demo.
Build Settings
Click on File > Build Settings... and select one of the following:
For Windows, set Target Platform to Windows and set Architecture to either x86 or x86 64.
Figure 3: Build Settings: PC
Note: Be sure to add any scenes you wish to include in your build to Scenes In Build..
Player Settings
Within the Build Settings pop-up, click Player Settings. In the Other Settings frame, select Virtual Reality
Supported. All additional required settings are enforced automatically.
Figure 5: Player Settings
In the Build Settings pop-up, select Build. If prompted, specify a name and location for the build.
If you are building in the same OS, the demo should start to run in full screen mode as a standalone
application.
Quality Settings
You may notice that the graphical fidelity is not as high as the pre-built demo. You will need to change some
additional project settings to get a better looking scene.
Navigate to Edit > Project Settings > Quality. Set the values in this menu to the following:
Figure 6: Quality settings for Oculus demo
The most important value to modify is Anti-aliasing. The anti-aliasing must be increased to compensate for the
stereo rendering, which reduces the effective horizontal resolution by 50%. An anti-aliasing value of 2X is ideal 4x may be used if you have performance to spare, and 8x usually isn't worth it.
Now rebuild the project again, and the quality should be at the same level as the pre-built demo.
Now that the project is properly configured for VR, its time to install and run the application.
PC builds create a single executable file that may be used in either Direct Display or Extended Display modes.
Build Settings
From the File menu, select Build Settings. From the Build Settings menu, select Android as the
platform. Set Texture Compression to ASTC.
Player Settings
1. Click the Player Settings button and select the Android tab. In the Other Settings frame, select
Virtual Reality Supported. All required settings are enforced automatically, but you may wish to make
additional settings as appropriate, such as enabling Multithreaded Rendering and setting Graphics APIs to
OpenGLES3.
Figure 7: Player Settings
2. Select the Splash Image section. For Mobile Splash image, choose a solid black texture.
Note: Custom Splash Screen support is not available with Unity Personal edition.
Design Considerations
Please review Design Guidelines in the Mobile SDK documentation if you have not already done so.
Start up Sequence
For good VR experiences, all graphics should be rendered such that the user is always viewing a proper threedimensional stereoscopic image. Additionally, head-tracking must be maintained at all times.
An example of how to do this during application start up is demonstrated in the SDKExamples Startup_Sample
scene:
Solid black splash image is shown for the minimum time possible.
A small test scene with 3D logo and 3D rotating widget or progress meter is immediately loaded.
While the small start up scene is active, the main scene is loaded in the background.
Once the main scene is fully loaded, the start scene transitions to the main scene using a fade.
Best Practices
Be Batch Friendly. Share materials and use a texture atlas when possible.
Prefer lightmapped, static geometry.
Prefer lightprobes instead of dynamic lighting for characters and moving objects.
Bake as much detail into the textures as possible. E.g., specular reflections, ambient occlusion.
Only render one view per eye. No shadow buffers, reflections, multi-camera setups, et cetera.
Keep the number of rendering passes to a minimum. No dynamic lighting, no post effects, don't resolve
buffers, dont use grabpass in a shader, et cetera.
Avoid alpha tested / pixel discard transparency. Alpha-testing incurs a high performance overhead.
Replace with alpha-blended if possible.
Keep alpha blended transparency to a minimum.
Use Texture Compression. Favor ASTC.
Check the Disable Depth and Stencil* checkbox in the Resolution and Presentation pane in Player Settings.
Be mindful of the total number of GameObjects and components your scenes use.
Model your game data and objects efficiently. You will generally have plenty of memory.
Minimize the number of objects that actually perform calculations in Update() or FixedUpdate().
Reduce or eliminate physics simulations when they are not actually needed.
Use object pools to respawn frequently-used effects or objects instead of allocating new ones at runtime.
Use pooled AudioSources versus PlayOneShot sounds, as the latter allocate a GameObject and destroy it
when the sound is done playing.
Avoid expensive mathematical operations whenever possible.
Cache frequently-used components and transforms to avoid lookups each frame.
Use the Unity Profiler to:
Identify expensive code and optimize as needed.
Identify and eliminate Garbage Collection allocations that occur each frame.
Identify and eliminate any spikes in performance during normal play.
Do not use Unitys OnGUI() calls.
Do not enable gyro or the accelerometer. In current versions of Unity, these features trigger calls to
expensive display calls.
All best practices for mobile app and game development generally apply.
Note: The Unity Profiler is not available for Unity Free.
Rendering Optimization
While building your app, the most important thing to keep in mind is to be conservative on performance from
the start.
Dynamic batching is used for moving objects and is applied automatically when objects meet certain criteria,
such as sharing the same material, not using real-time shadows, or not using multipass shaders. More
information on dynamic batching criteria may be found here: https://docs.unity3d.com/Documentation/Manual/
DrawCallBatching.html
Culling
Unity offers the ability to set manual per-layer culling distances on the camera via Per-Layer Cull Distance.
This may be useful for culling small objects that do not contribute to the scene when viewed from a given
distance. More information about how to set up culling distances may be found here: https://docs.unity3d.com/
Documentation/ScriptReference/Camera-layerCullDistances.html.
Unity also has an integrated Occlusion Culling system. The advice to early VR titles is to favor modest scenes
instead of open worlds, and Occlusion Culling may be overkill for modest scenes. More information about
the Occlusion Culling system can be found here: http://blogs.unity3d.com/2013/12/02/occlusion-culling-inunity-4-3-the-basics/.
Reducing Memory Bandwidth
Texture Compression: Texture compression offers a significant performance benefit. Favor ASTC
compressed texture formats.
Texture Mipmaps: Always use mipmaps for in-game textures. Fortunately, Unity automatically generates
mipmaps for textures on import. To see the available mipmapping options, switch Texture Type to
Advanced in the texture inspector.
Texture Filtering: Trilinear filtering is often a good idea for VR. It does have a performance cost, but it is
worth it. Anisotropic filtering may be used as well, but keep it to a single anisotropic texture lookup per
fragment.
Texture Sizes: Favor texture detail over geometric detail, e.g., use high-resolution textures over more
triangles. We have a lot of texture memory, and it is pretty much free from a performance standpoint. That
said, textures from the Asset Store often come at resolutions which are wasteful for mobile. You can often
reduce the size of these textures with no appreciable difference.
Framebuffer Format: Most scenes should be built to work with a 16 bit depth buffer resolution.
Additionally, if your world is mostly pre-lit to compressed textures, a 16 bit color buffer may be used.
Screen Resolution: Setting Screen.Resolution to a lower resolution may provide a sizeable speedup for
most Unity apps.
The Unity Profiler displays CPU utilization for the following categories: Rendering, Scripts, Physics,
GarbageCollector, and Vsync. It also provides detailed information regarding Rendering Statistics, Memory
Usage (including a breakdown of per-object type memory usage), Audio and Physics Simulation statistics.
GPU Usage data for Android is not available at this time.
The Unity profiler only displays performance metrics for your application. If your app isnt performing as
expected, you may need to gather information on what the entire system is doing. Show Rendering Statistics
Unity provides an option to display real-time rendering statistics, such as FPS, Draw Calls, Tri and Vert Counts,
VRAM usage.
While in the Game View, pressing the Stats button (circled in red in the upper-right of the following screenshot)
above the view window will display an overlay showing real-time render statistics.
General Issues
When switching between a mobile application and System Activities screen, the back button becomes
stuck in the "down" state. [Unity 5 with Mobile SDK 0.6.0.1, 0.6.1.0, 0.6.2.0]
A current workaround is to send an artificial back-button-up event on resume. If the user wants to go
immediately back to the System Activities from the app, they will need to press and hold the back button
longer than 0.75 seconds.
No VR support for Editor Game View [Legacy Integration packages with Unity versions prior to 4.6.7p4]
Fixed in Unity 4.6.8.
Slight increase in rendering latency for trivial scenes. [Legacy Integration 0.6.0.2, fixed since Integration
0.6.2]
Simple scenes (e.g., scenes that take < 3 ms to render) may show 2-3 ms higher latency with Integration 0.6.0.2.
Typical scenes take > 5 ms to render and should be unaffected.
D3D log errors about texture; random textures appear frozen full-screen instead of the eye buffer [Unity
5.0 - 5.1.1p2]
Linear lighting and MSAA are broken with VR. [Unity 5.1.2p3-5.1.3p1]
Mac will not vsync properly for now. [Utilities 0.1.0.0]
Unity Editor crashes in Game View when VR is enabled. [Unity 5.1.2p2]
This is a known issue. See Compatibility and Requirements for recommended Unity versions.
Unity 5 hangs while importing assets from SDKExamples [SDKExamples 0.1.0 Beta].
Unity 5 is known to import ETC2-compressed assets very slowly.
PC
Legacy Integration 0.6.0.1 and earlier are not compatible with Oculus Runtime for Windows 0.7.
The app does not launch as a VR app.
Verify that you are using a compatible runtime - see Compatibility and Requirements for more details.
Ensure you have administrator rights to the system where you are installing the integration. Verify that the HMD
is plugged in and working normally, and that you have installed the Oculus runtime. Also verify that you have
not selected D3D 9 or Windows GL as the renderer (Legacy Integration only).
Rift apps run in a window and are mirrored to the Rift in Direct Display mode. [Integration 0.6.0.0,
Integration 0.6.0.1, Utilities 0.1.0.0 Beta]
OS X
Mac Tearing [All first-party Unity VR in 5.1.0-5.1.2 using Utilities 0.1.0)]
Editor preview and standalone players do not vsync properly, resulting in a vertical tear and/or judder on DK2.
Android players are unaffected, even if built on a Mac.
Unity Editor crashes when building APK or pressing play in Play View; Mac standalone player crashes.
[Unity 4 with Oculus Runtime for OS X 0.4.4 and Legacy Integration 0.6.0.2 or 0.6.1]
Fixed in Legacy Integration 0.6.2.0. In older versions, update to Oculus Runtime for OS X 0.5.0.1. Before
updating your runtime, be sure to run uninstall.app (found in /Applications/Oculus/) to remove your previous
installation.
Mobile
Audio corruption with Android low-latency audio path. [Unity 4.6.1p4 - 4.6.7p2; 5.1.0f2 and up. Fixed
Unity 4.6.7p3 and up.]
This sporadic issue affects some developers using Unity versions built on Androids low-latency audio path
handling. Symptoms include sampling problems resulting in hitching and garbled playback speeds that do not
affect pitch.
This issue has been fixed in Unity 5.2.0b4 and up. Unity is aware of the issue and is working on a fix for all
versions.
Game scene is missing or just renders the background color when pressing Play in Unity. [Integration
0.6.0.0, Integration 0.6.0.1]
Check the [Project Path]/Assets/Plugins/ folder and make sure that the Oculus plugins have not moved. See the
Unity console for additional information.
Issues with updating to the latest Oculus Unity Integration with Team Licensing and Perforce Integration
enabled. [Integration 0.6.0.0, Integration 0.6.0.1]
If you have Team Licensing and Perforce Integration enabled, you may need to check out the OVR and Plugins
folders manually before importing the updated Unity package.
The app does not launch as a VR app.
Verify that you have selected Virtual Reality Enabled in Player Settings.
Contact Information
Questions?
Visit our developer support forums at https://developer.oculus.com
Our Support Center can be accessed at https://support.oculus.com.
You will also need to refer to the relevant Oculus SDK documentation, available for download here: https://
developer.oculus.com/documentation/
The final video in the series, "107. Publishing the game," describes building the Roll-a-ball game for play
in a web browser. You may skip this lesson if you wish for the purposes of this exercise, as we will follow a
different procedure for building a playable application (PC/Mac) or APK (Android).
Note: We refer to the assets, folders, and so forth by the names used in the Unity tutorial, so it is
helpful to follow the names they use in their example.
4. Duplicate your Roll-a-ball project (optional).
Once you have completed building Roll-a-ball, you may wish to create a duplicate Roll-a-ball project
specifically for VR development. It can be useful to retain a backup of the original unmodified Roll-a-ball
project in case you make mistakes or wish to work with it later without the VR assets.
To duplicate the Roll-a-ball project, simply navigate in your OS to the Unity project folder containing your
Roll-a-ball project, copy the folder and all of its contents, and rename it. For this tutorial, we will use the
project folder name Roll-a-ball-VR.
5. Launch the new project and prepare the game scene.
1. Launch Unity and select File > Open Project... and select the project folder location for Roll-a-ball-VR in
order to launch the project.
2. In your Project tab, open Assets > _Scenes and select "MiniGame."
3. Press F2 and rename the scene "VRMiniGame."
4. Open the scene "VRMiniGame."
Enter Play mode by pressing the play button. The Unity Game View preview will show the image
corresponding to the left eye buffer. If you are using the PC SDK, you will see the Health and Safety
Warning appear over the game; press any key to continue past it.
Figure 8: Roll-a-ball VR in Unity Scene and Game Views
Integration
PC SDK
Mobile SDK
Unity
11/16/2015
0.1.3.0 Beta
0.8.0.0
1.0.0
5.3.1p4
10/30/2015
0.1.3.0 Beta
0.8.0.0
0.6.2.0
5.2.2p2
10/1/2015
0.1.2.0 Beta
0.7.0.0
0.6.2.0
5.2.1p2
7/6/2015
0.1.0.0 Beta
0.6.0.1
0.5.0
5.1.1
Integration
PC SDK
Mobile SDK
Unity
10/30/2015
0.8.0.0
0.8.0.0
1.0.0
4.7.0f1
9/08/2015
0.6.2.0
0.7.0.0
0.6.2.0
4.6.7+
8/14/2015
0.6.1.0
0.6.0.1
0.6.1.0
4.6.7+
8/7/2015
0.6.0.2
0.6.0.1
0.6.0.1
4.6.7
6/25/2015
D 0.6.0.1
0.5.0.1
0.6.0.1
4.6
6/12/2015
M 0.6.0.1
0.5.0.1
0.6.0.1
4.6
5/15/2015
D 0.6.0.0
0.5.0.1
0.5.0
4.6
3/31/2015
M 0.5.0
0.5.0.1
0.5.0
4.6
3/26/2015
D 0.5.0.1
0.5.0.1
0.5.0
4.6
3/20/2015
M 0.4.3.1
0.4.4
0.4.3.1
4.5
2/27/2015
M 0.4.3
0.4.4
0.4.3
4.5
1/23/2015
M 0.4.2
0.3.2
0.4.2
4.5
1/7/2015
M 0.4.1
0.3.2
0.4.1
4.4
12/4/2014
D 0.4.4
0.4.4
0.4.0
4.6
11/12/2014
M 0.4.0
0.3.2
0.4.0
4.4
11/10/2014
D 0.4.3.1
0.4.3.1
N/A
4.5
10/24/2014
D 0.4.3
0.4.3
N/A
4.5
9/4/2014
D 0.4.2
0.4.2
N/A
4.5
8/11/2014
D 0.4.1
0.4.1
N/A
4.4
7/24/2014
D 0.4.0
0.4.0
N/A
4.4
5/22/2014
D 0.3.2
0.3.2
N/A
4.3
4/14/2014
D 0.3.1
0.3.1
N/A
4.3
10/10/2013
D 0.2.5
0.2.5
N/A
4.3
46|Release Notes|Unity
Release Notes
This section describes changes for each version release.
Unity|Release Notes|47
New Features
Redesigned input API for Oculus Touch controllers and Xbox gamepads.
Added h264 hardware-decoder plugin for Gear VR.
Added face-locked layer support to OVROverlay when parented to the camera.
Reduced latency in the pose used by the main thread for raycasting, etc.
Updated to PC SDK 0.7 and Mobile SDK 0.6.2.0.
Enabled VRSettings.renderScale on Gear VR.
Several minor performance optimizations.
SDKExamples
Restored MoviePlayerSample
API Changes
The Utilities package now requires Unity 5.1 or higher.
Added OVRInput API alpha. Refer to documentation for usage.
Exposed LeftHand/RightHand anchors for tracked controllers in OVRCameraRig.
Bug Fixes
Restored ability to toggle settings such as monoscopic rendering and position tracking.
HSWDismissed event is now correctly raised when the HSW is dismissed.
Fixed handedness of reported velocity and acceleration values.
OVRPlayerController now moves at a consistent speed regardless of scale.
Known Issues
Tearing in OS X: Editor preview and standalone players do not vsync properly, resulting in a vertical tear
and/or judder on DK2.
When switching between a mobile application and System Activities screen, the back button becomes stuck
in the "down" state. For more information and workarounds, please see Troubleshooting and Known Issues.
Utilities for Unity 0.1.0.0 Beta
Overview
This is the initial release of Oculus Utilities for Unity, for use with Unity versions 5.1.2 and later. The Utilities
extend Unity's built-in virtual reality support with the following features:
48|Release Notes|Unity
Known Issues
Pitch, roll, and translation are off for the tracking reference frame in Unity 5.1.1, especially in apps with
multiple scenes.
Mac OS X tearing. VSync is currently broken on the Mac, but works when you build for Gear VR.
Performance loss. CPU utilization may be slightly higher than in previous versions of Unity.
OVRPlayerController might end up in an unexpected rotation after OVRDisplay.RecenterPose() is called. To
fix it, call RecenterPose() again.
Unity|Release Notes|49
The source for the Unity SDKExample MediaSurface Plugin is now provided. The Media Surface Plugin provides
a native library which is used with the Android MediaPlayer for hardware decoding of a single video to a
texture. Note that the SDKExample MediaSurface Plugin is not intended to be production quality, and is
provided for reference purposes. We have made the source available in case you would like to modify it for
your use. The source and build files are located at the following SDK path: VrAppSupport/MediaSurfacePlugin.
This version adds an alpha release of OVRInput, which provides a unified input API for accessing Oculus Touch
and Microsoft Xbox controllers.
New Features
Added alpha OVRInput script to expose API for Oculus Touch and XInput-based controllers.
Now dynamically loads OpenGL ES symbols instead of hard-linking to libGLESv3.so. (Mobile)
API Changes
Now requires the new Android Plugin Java library OculusUtilities.jar (found in Assets/Plugins/Android).
Bug Fixes
Fixed Editor error message in Unity Free due to unsigned OVRPlugin.dll.
Fixed thread affinity failing to be set for the TimeWarp and DeviceManager threads. (Mobile)
Fixed device reset when repeatedly plugging and unplugging the Travel Adapter on the Galaxy SAMSUNG
S6. (Mobile)
Fixed app crash occurring when using Oculus Runtime for OS X earlier than 0.5.0.1.
Unity 4.x Legacy Integration 0.6.1.0
Overview of Major Changes
Legacy Integration 0.6.1.0 expands upon the changes in Unity 4.x PC Integration 0.6.0.2. It is fully compatible
with both our Mobile and PC SDKs.
For more information on important changes and updates relevant to this version, see the Release Notes for
Integration 0.6.0.2 below.
PC Developers
This release of the Unity Legacy Integration is compatible with the Oculus Runtime 0.6 and 0.7. All Unity
projects built with Unity 4 must update to this release, or they will not work on PCs using Runtime 0.7.
OS X Developers
Mac developers using Legacy Integration 0.6.1.0 must update to the Oculus Runtime for OS X 0.5.0.1. Before
updating your runtime, be sure to run uninstall.app (found in /Applications/Oculus/) to remove your previous
installation.
Mobile Developers
The MediaSurface functionality has been split from the main Unity Integration and provided as a separate
plugin, libOculusMediaSurface.so included with the Unity integration package.
New Features
SDKExamples
MoviePlayer_Sample now looks for media files in the folder Streaming Assets instead of following a hardcoded path on the internal sdcard (default mp4 provided).
50|Release Notes|Unity
MoviePlayer_Sample defaults to using Unity MovieTexture functionality on the PC (media file expected as
Ogg Theora).
API Changes
No longer required to issue ResetVrModeParms to dynamically adjust CPU and GPU clock levels.
Bug Fixes
Added back one frame of latency to Unity apps to avoid object motion judder by giving Unity apps one
frame of additional GPU time (0.5.1 performance parity).
Unity 4.x PC Integration 0.6.0.2
Overview of Major Changes
Note: This release is intended for PC development only. Mobile developers should wait for Legacy
Integration version 0.6.1.0, which will ship very soon.
This release of the Unity Legacy Integration is compatible with the Oculus Runtime 0.6 and 0.7. All Unity
projects built with Unity 4 must update to this release, or they will not work on PCs using Runtime 0.7.
In most cases, migrating to this version of the legacy integration will be easy - simply open your project in
Unity, import the custom Integration unityPackage, and rebuild.
If you have previously used our C API wrappers in OvrCapi.cs, note that they have been removed and you will
need to write your own native plugins or replacement wrappers to access functionality from LibOVRRT. This
change is also required to use CAPI with our Unity 5 Utilities, so writing your own plugins or wrappers now will
help prepare for your migration to Unity 5.
A single executable file is now produced for PC builds, which will work in both Extended and Direct Display
modes.
This version removes support for D3D 9 and Windows GL.
Mac developers using Legacy Integration 0.6.0.2 must update to the Oculus Runtime for OS X 0.5.0.1. Before
updating your runtime, be sure to run uninstall.app (found in /Applications/Oculus/) to remove your previous
installation.
New Features
Compatible with Oculus Runtime versions 0.6 and 0.7.
PC builds now produce a single executable file for use in both Extended and Direct Display modes.
Oculus runtime log messages now visible in the Unity console.
Unity Editor Game View displays undistorted monoscopic preview.
No longer necessary to rotate Mac monitor for DK2 in System Preferences->Displays.
API Changes
Removed all C API wrappers from OvrCapi.cs.
Removed D3D9, Windows GL, and Linux support.
Bug Fixes
Fixed C# script problem that caused D3D11 Exclusive Mode errors.
Fixed several Editor Game View issues:
Unity|Release Notes|51
52|Release Notes|Unity
Unity|Release Notes|53
VrPlatform entitlement checking is now disabled by default in Unity; handling for native development is
unchanged. If your application requires this feature, please refer to the Mobile SDK Documentation for
information on how to enable entitlement checking.
New Features
Synced with the Oculus PC SDK 0.5.0.1 Beta.
VrPlatform entitlement checking is now disabled by default.
Bug Fixes
Health and Safety Warning no longer displays in editor Play Mode if a DK2 is not attached.
Known Issues
For use with the Mobile SDK, we recommend Unity versions 4.6.3, which includes Android 5.0 - Lollipop
support as well as important Android bug fixes. While the Mobile SDK is compatible with Unity 5.0.0p2
and higher, several issues are still known to exist, including an Android ION memory leak and compatibility
issues with OpenGL ES 3.0. Please check back for updates.
Mobile Unity Integration 0.5.0
Overview of Major Changes
The Mobile Unity Integration is now synced with the Oculus PC SDK 0.5.0.1 Beta. Please ensure you have
installed the corresponding 0.5.0.1 Oculus runtime; it can be found at the following location: https://
developer.oculus.com/downloads/
VrPlatform entitlement checking is now disabled by default in Unity; handling for native development is
unchanged. If your application requires this feature, please refer to the Mobile SDK Documentation for
information on how to enable entitlement checking.
New Features
Synced with the Oculus PC SDK 0.5.0.1 Beta.
VrPlatform entitlement checking is now disabled by default.
Bug Fixes
Health and Safety Warning no longer displays in editor Play Mode if a DK2 is not attached.
Known Issues
For use with the Mobile SDK, we recommend Unity versions 4.6.3, which includes Android 5.0 - Lollipop
support as well as important Android bug fixes. While the Mobile SDK is compatible with Unity 5.0.0p2
and higher, several issues are still known to exist, including an Android ION memory leak and compatibility
issues with OpenGL ES 3.0. Please check back for updates.
54|Release Notes|Unity
Unity|Release Notes|55
OVRCameraController OVRCameraRig
OVRCamera
OVRTracker
OVR.Hmd Ovr.Hmd
Tracking acquired/lost
HSWDismissed
Get/Set*(ref *) methods
Replaced by properties.
Behavior Changes
Upgrade Procedure
To upgrade, follow these steps:
1. Ensure you didnt modify the structure of the OVRCameraController prefab. If your eye cameras are on
GameObjects named CameraLeft and CameraRight which are children of the OVRCameraController
GameObject (the default), then the prefab should cleanly upgrade to OVRCameraRig and continue to work
properly with the new integration.
2. Write down or take a screenshot of your settings from the inspectors for OVRCameraController,
OVRPlayerController, and OVRDevice. You will have to re-apply them later.
3. Remove the old integration by deleting the following from your project:
OVR folder
OVR Internal folder (if applicable)
Moonlight folder (if applicable)
Any file in the Plugins folder with Oculus or OVR in the name
56|Release Notes|Unity
4.
5.
6.
7.
8.
9.
Android-specific assets in the Plugins/Android folder, including: vrlib.jar, libOculusPlugin.so, res/raw and
res/values folders
Import the new integration.
Click Assets -> Import Package -> Custom Package
Open OculusUnityIntegration.unitypackage
Click Import All.
Fix any compiler errors in your scripts. Refer to the API changes described above. Note that the substitution
of prefabs does not take place until after all script compile errors have been fixed.
Re-apply your previous settings to OVRCameraRig, OVRPlayerController, and OVRManager. Note that the
runtime camera positions have been adjusted to better match the camera positions set in the Unity editor. If
this is undesired, you can get back to the previous positions by adding a small offset to your camera:
a. Adjust the camera's y-position.
...
----------------------------------------------------------------------
Unity|Release Notes|57
OVRDevice.ResetOrientation();
to
OVRManager.display.RecenterPose();
---------------------------------------------------------------------cameraController.ReturnToLauncher();
to
OVRManager.instance.ReturnToLauncher();
---------------------------------------------------------------------OVRDevice.GetBatteryTemperature();
OVRDevice.GetBatteryLevel();
to
OVRManager.batteryTemperature
OVRManager.batteryLevel
---------------------------------------------------------------------OrientationOffset
Set rotation on the TrackingSpace game object instead.
---------------------------------------------------------------------FollowOrientation
---------------------------------------------------------------------FollowOrientation is no longer necessary since OVRCameraRig applies tracking
in local space. You are free to script the rigs pose or make it a child of
another GameObject.