Earlier we look at getting started doing Gear VR development using Samsung’s GearVRf library. In that tutorial I mentioned a few times that it is a great deal easier to get started doing Gear VR development using the Unity game engine. Today we are going to look at the process of getting a game up and running using the Unity game engine. This tutorial is GearVR specific, however it should be just as applicable for the Oculus Rift.
Truth of the matter is getting started with Unity is exceptionally easy, but…
The information out there is all out of date and makes the learning curve much harder than it used to be. First off, Samsung make a set of utilities available and you need to make sure you get the newest version. However, Unity now has VR built in out of the box, so you don’t need to do anything at all. This renders almost all of the existing getting started type tutorials completely wrong.
There is a video version of this tutorial available here.
First off, create a project like normal, no need to do anything special.
Now select Build Settings in the File menu
Select Android, then Player Settings…
Now select Virtual Reality Supported. Also be sure to set your bundle identifer and optionally the Minimum API Level (the lowest possible level is a Galaxy Note running 4.4):
If you run it now you will get the following error:
This is because the GearVR wont allow your app to run without the Oculus key. To get this you need a (free) developer account from Oculus and register your device using this form. That will generate a file that needs to be copied into your project.
Inside your Unity project, locate the Assets directory and create the following directories Plugins\Android\Assets and copy the signing key in, here is mine:
Your game should now run just fine on your device.
Oculus Utilities for Unity 5
The “old” way of supporting GearVR and Oculus Rift in Unity involved importing a set of utilities called the Oculus Utility of Unity 5. Since these were released however Oculus and Unity have worked to make the integration in Unity more complete. That said, the transition isn’t complete as of writing. You still don’t have access to the universal menu or overlays using Unity so you still may have to use the Oculus Utilities. Fortunately they can still be imported and exist side by side with a default Unity install.
In addition to the Oculus Utilities of Unity there is also a set of example projects that you can import. There is also a guide to Unity 5 integration available on Oculus, although be aware that parts of it are now obsolete.
Unity VR Samples
There is also a pretty significant set of samples illustrating using VR in Unity available on the Unity Store. Simply create an empty project and import in the example. These VR Samples illustrate a number of different concepts required for working with VR in Unity.
In time, more and more functionality should be built into Unity, making this process even easier.