This article covers some basic topics in creating a Google Cardboard VR app using Unity.

This article is based on GVR SDK for Unity v1.130.1.

We will begin with getting the Google Cardboard (GVR) SDK and setup a blank scene with no assets.  We will then get some sample assets from the Asset Store and setup the scene.  For this demo I’m going to be using the Free Hand Painted Forest Environment asset from the Asset Store.  Instead of using this, you can build your own environment, but it gets us going quickly.

To being with go ahead and create a new 3D project in Unity.

1. Getting The GVR SDK

Visit the GVR SDK for Unity Releases page and download the latest unitypackage file.  Once it is downloaded, start Unity and create a new project.  Click on Assets > Import Package > Custom Package… menu and select the GoogleVRForUnity_*.unitypackage file you have just downloaded.  Leave all assets selected and click Import.

Once completed you will see a folder called GoogleVR under the Assets folder in your Project panel (Windows > Project).

2. Setting Up The Prefabs From GVR

First of all create a new scene.  Create a new empty Game Object and call it Player.  Move the existing camera under the Player game object and call it Main Camera.

We need some of the prefabs provided by the GVR SDK. Open up the GoogleVR folder in the Assets folder in the Project panel.  Under GoogleVR there is a folder called Prefabs. Drag the following prefabs into the scene hierarchy.

  1. GvrEventSystem – drag it to the root of the hierarchy. Drop-in replacement for Unity’s Event System.
  2. GvrEditorEmulator – drag it to the root of the hierarchy. Provides in-editor emulation of head movement and controller input.
  3. GvrRecticlePointer – drag it under the ‘Main Camera’. Provides a gaze-based reticle pointer that supports Cardboard viewer button input.

Your hierarchy should look like this.

3. Setting Up The Components For the Assets

The assets we have now setup require a number of components to to work within a VR environment.

  1. Select the Main Camera.  Add a component called ‘Gvr Pointer Physics Raycaster’. It behaves similarly to the standards Physics raycaster, except that it utilises raycast modes specifically for GVR.  So we need it to interact with objects in our VR environment using GVR.

4. Setup the Build Settings

By default Unity is not setup to build for mobile platforms.  For this demo we want to build the output for and Android device.  Go to File > Build Settings.

  1. Click on ‘Add Open Scenes’ button to add the current scene to the Scenes In Build list.
  2. Highlight the Android platform on the list of platforms and then click on the ‘Switch Platform’ button.
  3. Once Unity has switched the platform, click on the ‘Player Settings…’ button.  The Player Settings will be loaded on the Inspector panel.  This will allow you change various aspects of the app itself from the name to the version of Android it will support.
  4. Open up the Other Settings panel.  Provide the identification details required for your app and Android version information.
  5. Once you have modified all required parameters, go to the last section which is called ‘XR Settings’.  Make sure the ‘Virtual Reality Support’ is ticked.  Once it is ticked, you need to select one or more Virtual Reality  SDKs.  Select Cardboard.

5. Play The Scene In The Editor

All we have done so far is to setup an empty scene with the foundation to build a VR app.  It’s time to see if it works.  Add a cube to the scene so there is something to see and then press the Play button.

When you play the scene in the editor, you will not see a dual screen as you might expect in an actual mobile device.  This is not supported in the Unity Editor any more.  However, you can still use your mouse to look around your scene while pressing the Alt button.

Once you are able to test the scene, you can add any object to your scene and create an environment you want to walk through.