Unity5_Banner

Kicking and screaming – upgrading a GearVR project to Unity 5

By JC on April 26th, 2015

Development on Smash Hit Plunder has been going for about 10 months now, and with multiple game modes, several rounds of optimisation and lots of user testing it’s a surprisingly complicated game under the hood. So when it came to upgrading to Unity 5, we weren’t looking forward to it.


Since the VR Game Jam is going on right now there’s loads of people trying to get Unity 5 running on the Gear VR, and lots of fragmented information on the latest gotchas and snags that can trip people up.


Here’s our upgrade hints, awkward snags and potential workarounds.


The Obvious Stuff

Make sure you’re on the absolutely latest version of Unity. As of right now, that’s 5.0.1p2. Additionally, the latest Oculus mobile sdk is 0.5.0.


And take a backup – or better yet make a branch in source control. You are using source control aren’t you? Phew. Good.

The Basics

You’ll need to make sure you’re forcing OpenGL ES 2.0, which you can do in your player settings:



PlayerSettingsForceES2_0

And you’ll also need to do in your Android manifest.xml too:



AndroidManifestEs2_0

Depending on how you created your project, remember to check your oculussig_XXXXX files are still in the correct place in Assets/Plugins/Android/assets/, or generate these if you’ve not done so before over here: https://developer.oculus.com/osig/


If you’re lucky, everything will just work now. If not, read on…


Verification via logcat

Most Android developers will know about this, but if you’re new then it’s an easy trick to miss – you can still get debug output out of a running Android build via logcat. Since the Gear VR is taking up the usb port, you first have to reconnect over wifi:



LogcatWifi

You need to do this while the phone is still connected via usb, but before you start your app (or while it’s still on the ‘Please insert into the Gear VR’ pop-up).


Unity’s Debug.LogXXX messages will all be routed here, and you should probably verify you’re getting an ES 2.0 context via this method. If you’re doing lots of debugging via logcat then I like to download Eclipse and use it’s ddms view to be able to filter and search the logcat output.


Still not working? Nah, me neither.



Segfault

Ugh. A crash on near startup that logcat shows is when Unity is doing a low-level ES call. Without the source or a way to identify the geometry in question, we were pretty much left trying to do a Binary Chop.


Turns out there’s some bugs with the dynamic batching that we were hitting – but only with a particular shader. Fortunately we don’t really need that shader anymore, so we can just drop it. To find this I stripped the whole game back to just a title screen and added in sections of the game until things started crashing again. If you’re getting hard crashes then try disabling dynamic batching (in the player settings) and see if that helps.


Ok, this will work now ohwaitit’sstillcrashingonstartup.



AnalyticsCrash

That, amusingly enough, is Google Analytics reporting it’s own crash. No, I’m not even sure how that’s possible either. Either way, this can be fixed by nuking the plugin and redownloading the latest version. If you have any other similar 3rd party plugins, consider doing the same.


Vanishing Eyeballs

There was one big issue after fixing all of the above – items would vanish from the left eye’s view, or become very dark, producing some very weird looking results. This seems to be quite a common issue, with no real agreement on how to fix it.


For us, the bug seems to occur at the intersection of three different unity engine sub-features:
– Dynamic batching
– Multithreaded rendering
– Vertex lit pipeline


Various combinations of these would either work or not work, with various performance knock-on effects. If you can, disable dynamic batching and multithreaded rendering and see if that helps. Unfortunately we heavily rely on dynamic batching to render at a decent framerate, so that wasn’t really an option for us.


The final trick we’ve found is to switch to the ‘forward’ rendering path, but with a pixel light count of 0, and with multithreaded rendering turned off. That still gets us a nice 60Hz framerate but with none of the vanishing objects. Depending on your game, you might need a different combination.


Other Voodoo

Here’s a bunch of additional hints gathered from around the web. None of these seemed to work for us, but they did for other people, so they’re probably worth a shot:
– Disable anti-aliasing on the left and right eyes in the OvrCameraRig prefab
– Enable ‘optimise builds for Rift’ in the preferences (Edit->Preferences). Be careful as this is a per-install setting, not per project
– Try moving your OvrCameraRig to the root of the hierarchy


Unfortunately debugging low-level issues is always going to be painful without source access or the ability to natively debug, but hopefully some or all of the above will help anyone else migrating to Unity 5.


If you’d like to play Smash Hit Plunder, then our free demo is available in the Oculus store for Gear VR now.


Tags: , , ,