Building virtual reality apps for each platform in Unity can sometimes have a few gotchas. I’ve spent the past month or so moving a Unity Google Cardboard app into Gear VR, stumbling upon a few quirks and missing a few steps. I thought I’d list the tips I’d come across after it all, to help those who attempt this after me!

A Gear VR headset with the Unity splash screen visualisation

Some tips for those building for Gear VR in Unity

What should my “Build Settings” and “Player Settings” be?

The first step in getting an app running properly on Gear VR is having the correct “Build Settings” and “Player Settings” for your Unity project. This bit isn’t too complicated, but when things stop working right, it really makes you question yourself and whether you’ve got them set up right! Here are how I’ve set up my own project for Gear VR:

  1. Go to File > Build Settings…
  2. Choose “Android” for your platform (select it and then click “Switch Platform”)
  3. Choose “ASTC” for “Texture Compression” (I’m not actually sure if this makes too much difference sometimes, but the Oculus Developer Center docs recommend this)
  4. Then click “Player Settings” to bring up those settings on the right.
  5. In those settings, click the Android tab (it should already be selected if you’ve chosen “Android” as your build platform but good to check if you’re totally new at this)
  6. The most important step is right here — Tick “Virtual Reality Supported”. This is especially important if you’ve been building for other platforms as it’s incredibly easy to miss. I’ve missed this checkbox a bunch of times when switching between Google Cardboard’s old SDK and Gear VR development. It can be a time-consuming thing to forget after an export!
  7. Under “Virtual Reality SDKs”, click the + button and add “Oculus”. This is the same setting as developing for the Oculus Rift, they share the same set up within Unity.

The settings should look like so:

Screenshots of both settings mentioned above

Setting up the Build Settings and Player Settings correctly

You will need an Oculus Signature File

Seeing the Gear VR error “thread priority security exception make sure the apk is signed” when running your app? This means your phone doesn’t see an Oculus Signature File in your Unity project build.

This isn’t too hard to generate, but if you’ve been largely working with Google Cardboard apps or you’ve switched phones mid-development, this is really easy to overlook! Your app needs to have an Oculus Signature File inside it to give your phone permission to run the VR side of things in your test app.

“All Gear VR applications must be signed with an Oculus Signature File (osig) during development to access low-level VR functionality on your mobile device. This signature comes in the form of an Oculus-issued file that you include in your application.” — Oculus, Preparing for Mobile Development

You can generate an OSIG file using the Oculus Signature File (osig) Generator. They provide full details of how to generate the file for your particular phone, just make sure you’ve got it connected over USB.

Once you’ve got it downloaded from that tool, add it into the Project/Assets/Plugins/Android/assets/ folder of your project.

You don’t need to have your phone in the Gear VR headset to test!

A screenshot of the Gear VR Service options

Tap “VR Service Version” a bunch of times and you’ll receive the power of Developer Mode!

Turns out, you can enable Developer Mode within the Gear VR service on your phone which lets you run Gear VR apps without needing to connect them to the headset. This was an absolute revelation when I uncovered this.

To do so:

  1. Install an application with an OSIG file onto your phone. This is apparently necessary before the rest will work!
  2. Then on your phone, go to Settings > Application Manager.
  3. Find and open “Gear VR Service”
  4. On newer versions of Android (Android 7.0 Nougat and higher), click on “Storage”.
  5. Then click “Manage Storage”. I believe older versions of Android have this button earlier in the process!
  6. Click repeatedly on “VR Service Version” until a hidden option for “Developer Mode” appears!
  7. Turn that “Developer Mode” option on!
  8. The “Add icon to app list” is also handy so you can find the “Gear VR Service” in your application list to easily toggle Developer Mode on and off easier.

How do I see logs from my Gear VR app when it’s not connected to my PC?

Now here’s an interesting question — you can’t see logs when you’re wearing the Gear VR headset. You also can’t really have it connected to your PC when it’s also connected to the Gear VR headset! So… how do you see logs? The answer is actually pretty neat — you can connect to your phone’s logs over Wi-Fi!

  1. Connect your phone and your computer to the same Wi-Fi network.
  2. Connect up your Samsung phone to your computer over USB to start with.
  3. We then tell the phone to listen for a TCP/IP connection on port 5555. Open up the Command Prompt (or Terminal on Mac) and type in the following:
    adb tcpip 5555
  4. That should show some sign of success, for me, it looked like so in the command prompt:
    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    restarting in TCP mode port: 5555
  5. You can remove your phone at this point! It is free from the constraints of a USB cable!
  6. In order to connect to the phone from this point on, you’ll need its IP address. You can find that at Settings > About tablet (or About phone) > Status > IP address.
  7. Once you know the phone’s IP address, you can connect to it using the following terminal command:
    adb connect (that IP address you just found out)

    For example, if the IP address was 192.168.13.37:

    adb connect 192.168.13.37
  8. When that command is successful, it should say the following:
    connected to 192.168.13.37:5555
  9. Once you’ve run that, you can double check that the phone is connected using the following command:
    adb devices

    It should show something like the following if you are connected successfully:

    List of devices attached
    192.168.13.37:5555        device
  10. You can then see logs from that phone using:
    adb logcat
  11. That shows every single log on your phone! Chances are… that’s way too many logs. The simplest way to reduce this down is by filtering it like so:
    adb logcat -s Unity

    If that doesn’t show the sorts of logs you are looking for, this answer in the Unity forums has a wider net of logs it can capture that can relate to Unity:

    adb logcat -s Unity ActivityManager PackageManager dalvikvm DEBUG
  12. Too messy still in the command line? I know how you feel. It turns out Android Studio has a cleaner view of logs coming from your phone which you can filter in real time!To do so, I just create a blank project in Android Studio and then use the “Android Monitor” at the bottom of the interface. There is a filter spot where you can type in things like “Unity” and have the streaming logs filter straight away:

    A screenshot of filtering logs with the keyword Unity in Android Studio's Android Monitor

    Filtering logs in Android Studio’s Android Monitor

Note: If you switch over to Wi-Fi and haven’t got your OSIG file generated yet, you will need to reconnect your phone via USB first — you can’t retrieve the device ID needed unless connected over USB.

You don’t need to change the Android Manifest file

While debugging and struggling with some bugs, I turned to editing the manifest file… that’s not the right option. Unity makes this automatically:

“During the build process, Unity projects with VR support enabled are packaged with an automatically-generated manifest which is configured to meet our requirements (landscape orientation, vr_only, et cetera).” — Unity, Building Mobile Applications

You can’t test easily within Unity’s player… got a DK2?

So… you can’t really hit the Play button in the Unity editor and test your app. Instead, you’ve gotta upload it onto your phone every time. This can drive you a little crazy after a while. There’s a workaround but it’s not likely to be available to everyone — use an Oculus DK2.
If you’ve got a spare Oculus DK2 around, you can actually connect it up to your computer to do quick testing without needing to export the whole project. Just plug in your DK2 and then press the Play button in Unity!

Keep in mind that this isn’t necessarily going to be exactly what it would be like on the Gear VR, so you will want to test properly on that as well:

“The rendering path for Android applications differs substantially from the rendering path used for Rift application previews and builds, and you may notice important differences in the look-and-feel and performance.” — Oculus, Preparing for Mobile Development

Be careful with Unity 5.5.2

The latest stable version of Unity (at the time of writing) is Unity 5.5.2, however, I’ve had issues getting Gear VR projects to export and play successfully in VR mode using this version. If you’re having issues seeing your app in VR and you’ve set all the settings correct… try dropping back to Unity 5.5.1 and see if that resolves it for now.

Got your own tips?

Got any tips that I didn’t mention? Feel free to share them in the comments below or get in touch with me on Twitter at @thatpatrickguy! I’d love to hear them!

Thanks for reading! Dev Diner is a new hub for developers keen to keep up with emerging tech.
Know others who might want to read it too? Please like and share this post with them!

Would you like to republish this article in your own publication?
Contact Dev Diner to request official republication of this article.

Comments

Nice tips, thanks Patrick!

A couple more tips that I have, if you plan on using swipes on the touchpad for GearVR, it’s beneficial to import the Oculus Utilities for Unity so you can use basic swipe events without having to write your own solution.

If you do use OVRInput swipes in your GearVR apps, I find that it’s more beneficial (if can afford one) to use the Oculus Rift CV1 instead as you can easily map the swipes to the CV1’s remote if you use the Oculus Utilities for Unity.

How about publishing GearVR apps on Playstore.!? IS IT POSSIBLE ? Or it has to be from Oculus store..?

I think you can publish them on the Play Store, but Gear VR users might not look there as often for VR apps. I’ve seen some Gear VR apps on the Play Store, so I assume it works a-okay 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Want more?