Virtual Reality Set Up for the GearVR in Unity

 
Let’s go over Samsung’s virtual reality device, the Samsung GearVR, and connecting it with Unity. Similar to the last setup tutorials (DayDream & Oculus), we’ll start with a video guide from Usman:



 

Skip to the Technical Steps

 

Starting with the Unity Settings

 
1. In this step, we’re going to prep your Unity project for mobile VR development. First, head up to your File menu and select “Build Settings.” Get used to this, because we’re going to be returning to it for the next few steps. In the Build Settings window, click on “Android” in the Platforms list to highlight it. Now that the window displays options for the Android platform, click the dropdown Texture Compression menu and select “ASTC.”

2. Okay, round two. Back to File > Build Settings… but this time we’re going to click on “Player Settings…” at the bottom of the window. This will populate your Inspector with player settings. Close the Build Settings window and find your Inspector (on the right-hand side of your main Unity window). In the Inspector, expand the XR Settings menu and check the box next to “Virtual Reality Supported.” This will expand a “Virtual Reality SDKs” menu. Click the + and then click on “Oculus” to add it to the list. This seems a little counter-intuitive since we’re prepping Unity to develop for GearVR, but it actually makes sense, because GearVR relies on Oculus developer tools. Cool, right?

3. Let’s leave XR Settings and make some changes to other player settings while we’re in the Inspector. Go ahead and expand the Other Settings menu in the same area of the Inspector. In the Package Name field under “Identification,” enter a unique package name. You can make up any name, as long as it follows the convention “.com.something.something.” Then find the field for Minimum API Level for GearVR and select “Android 6.0 Marshmallow (API level 23).”

4. Finally, head into the Edit menu at the top and select Project Settings then Editor. The Inspector will change to display Editor Settings in place of the Player Settings you’ve been adjusting. In the first section (Unity Remote), click the Device drop down menu and select “Any Android Device.”

Importing the “Good Old” Oculus Integration

 
5. Before we import Oculus Integration, we need to find it. Look for the search bar in the middle of your main Unity window. Great! Now type “Oculus Integration” into that bar and wait a few seconds while Unity searches the Asset Store. Once the Oculus Integration asset shows up, double-click it. The Inspector will change to display asset options. Click “Import package” and enter your Asset Store login credentials to initiate the download. Follow the steps to import the package into Unity.

Connect Your App

 
6. In order to develop for GearVR, you’re going to need to connect your build to the Oculus ecosystem with an Oculus Signature File. It’s easy, which is good, because you’ll need to repeat this step if you’re building to test on multiple devices before you publish the application.

7. First, you’ll need to head over to Oculus and log into your Oculus account. (If you don’t already have an account, it’s easy to create one.) Then, find your mobile device ID. If you’re not sure how to do this, take a look at the Gear VR section of our guide to mobile device setup for VR development. Finding your device ID is outlined in Step 4.

8. Once you’ve found your device ID, enter it in the OSIG generator on the Oculus site, then generate the signature file. Now head back to Unity, but keep that Oculus window open so you can return to it and copy the signature file code.

9. After you imported Oculus Integration, Unity should have generated an assets directory that looks like this: Assets/Plugins/Android/assets. If you don’t have one, create it. Then paste your new Oculus signature file into that assets folder.

A Couple More Downloads

 
10. In this step, we’re going to connect some development packages to your project to bridge the gap between Unity and your mobile device.

11. In the Edit menu, click on Preferences to open the Unity Preferences window. Choose the External Tools tab on the left and find the NDK field under “Android.” Click the download button next to that field. Your browser will open with an active download of the Android NDK, and you can go grab yourself a coffee while you wait (it won’t be long!). Once you have the file, extract it.

12. Then, back in the Unity Preferences menu (and still in the External Tools tab), click “Browse” next to the NDK path. Find the file you just downloaded, and select it.

We’re done with the NDK. Now, hit the browse button next to the SDK path. In this window, you’ll want to select the root folder for the SDK directory. Confused? It should look something like this: C:\Users\your username\AppData\Local\Android\SDK.

Load the Scene!

 
13. The first thing we’re going to do in this step is to load the demo scene. To do it, go to your Assets tab. (It’s the area that fills the bottom of the main Unity window). Make sure “Assets” is highlighted on the left, then navigate to the OVR folder, then to Scenes, then Room. Double click on “Room” to load the demo scene.

Download our 10-week VR Development with Unity Course Syllabus


 

If You Are Having Trouble

 
An error window may pop up stating that Unity was unable to find a list of devices. No problem! We need to delete a file in your SDK root folder, so first let’s figure out where that is. Open Edit > Preferences and click on the External Tools tab. The file you want is in the SDK field. Copy and paste that location, or navigate to it, in your File Explorer or Finder.

In your File Explorer, in that main SDK root folder, delete the Tools folder. Then download SDK tools through this link: http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip. After the file is done downloading, extract it and move it to that main Android SDK root folder you deleted the other Tools folder from. Perfect! You should now be able to build and run your project in Unity.

When building your project and you come across an error stating it was unable to find a list of devices:

Happy building!

Download VR Course Syllabus
 

Technical Steps:

  1. Go to Build Settings > switch platform to Android/iOS and Texture Compression to ASTC.
  2. Build Settings > Player Settings > XR Settings and check Virtual Reality Supported and add Oculus to the list by clicking the plus sign.
  3. In Player Settings, go to Other Settings>Bundle Identification and enter a unique package name.
  4. Select Minimum API Level for GearVR: Android 6.0 Marshmallow (API level 23).
  5. Edit > Project Settings > Editor > Device and select Any Android Device.
  6. In the Asset Store (Click Window > Asset Store), search for “Oculus Integration”, import it.
  7. Create an Oculus Signature File. Go to https://dashboard.oculus.com/tools/osig-generator/ and enter your Device ID(see step 3 The Mobile Device). An Oculus account is required.
  8. Copy the signature file into your Asset folder. After importing “Oculus Integration” you should have a directory as follows: Assets/Plugins/Android/assets. Create it if nonexistent.
  9. Download and Install Android SDK Tools: https://developer.android.com/studio/index.html
  10. Download and Install Java SE Dev Kit: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  11. Edit > Preferences > External Tools and click download next to NDK, extract the zip file where you want and select the directory for the newly extracted root folder of the NDK after clicking browse next to NDK in Unity.
  12. Edit > Preferences > External Tools and select Browse next to SDK, select the root folder for the SDK directory. Default: C:\Users\your username\AppData\Local\Android\SDK
  13. Load the demo scene. Assets > OVR > Scenes > Room