Combining Samsung Gear VR with Google Cardboard

Thinking about making Gear VR and Cardboard work together sounds very easy in theory. All you need to do is turn off all the Cardboard scripts and turn on Virtual Reality Supported inside Unity player settings. Well, after almost eight hours of trying different things it didn’t pan out the way I had hoped, but I’m going to make it easy and explain what to do to get it working.

The first part is to get the plain stereoscopic camera to work both in Cardboard and Gear. Instead of manually checking and setting different game objects active or inactive it is much easier to make an editor script to do the work for you with the click of a button. So, to make an editor script you create new C# script inside a new folder called “Editor” and make sure it doesn’t extend monodevelop and is using unityeditor. You can get rid of the Update and Start functions. You should have an empty class just like the one below.

using UnityEngine;
using UnityEditor;

public class ExampleEditorScript{


After that you can tell it what you want it to do. Right now we need it to turn on/off cardboard features and virtual reality support. I’m sure you can handle that, there are just a couple lines of code that caught me for awhile. The first is how to put a menu item on the main menu bar in Unity, which is shown below.

[MenuItem("Main Menu Example Item/Example Button")]
static void ExampleButtonFunction(){


The next thing is telling Unity that you want virtual reality, which is easy. All you need to do is call PlayerSettings.virtualRealitySupported. After that it is important to set the Cardboard and CardboardHead scripts to stop vr and head tracking. Getting those are easy enough, just do regular GameObject.Find for each of them. Set the variables you want changed. Then the tricky part is updating them. You have to tell Unity that those variables updated in order for the changes to hold.


That code tells Unity to set the variables, just make sure you pass in the cardboard and cardboardHead objects. And there it is, just click a button and build to either Cardboard or Gear VR. Now, you are probably asking yourself, “Why did he spend eight hours on this?” Well, making the stereoscopic rendering to work is the easy part. The hard part is getting gaze input to work together, which I’ll save for the next post. I will say one thing about it though, do not expect it to work in Unity beta.