Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
3. January 2016

 

Earlier we look at getting started doing Gear VR development using Samsung’s GearVRf library.  In that tutorial I mentioned a few times that it is a great deal easier to get started doing Gear VR development using the Unity game engine.  Today we are going to look at the process of getting a game up and running using the Unity game engine.  This tutorial is GearVR specific, however it should be just as applicable for the Oculus Rift.

 

Truth of the matter is getting started with Unity is exceptionally easy, but…

 

The information out there is all out of date and makes the learning curve much harder than it used to be.  First off, Samsung make a set of utilities available and you need to make sure you get the newest version.  However, Unity now has VR built in out of the box, so you don’t need to do anything at all.  This renders almost all of the existing getting started type tutorials completely wrong.

There is a video version of this tutorial available here.

Getting Started

 

First off, create a project like normal, no need to do anything special.

image

 

Now select Build Settings in the File menu

image

 

Select Android, then Player Settings…

image

 

Now select Virtual Reality Supported.  Also be sure to set your bundle identifer and optionally the Minimum API Level (the lowest possible level is a Galaxy Note running 4.4):

image

 

If you run it now you will get the following error:

image

 

This is because the GearVR wont allow your app to run without the Oculus key.  To get this you need a (free) developer account from Oculus and register your device using this form.  That will generate a file that needs to be copied into your project.

Inside your Unity project, locate the Assets directory and create the following directories Plugins\Android\Assets and copy the signing key in, here is mine:

image

 

Your game should now run just fine on your device.

 

Oculus Utilities for Unity 5

 

The “old” way of supporting GearVR and Oculus Rift in Unity involved importing a set of utilities called the Oculus Utility of Unity 5.  Since these were released however Oculus and Unity have worked to make the integration in Unity more complete.  That said, the transition isn’t complete as of writing.  You still don’t have access to the universal menu or overlays using Unity so you still may have to use the Oculus Utilities.  Fortunately they can still be imported and exist side by side with a default Unity install.

 

In addition to the Oculus Utilities of Unity there is also a set of example projects that you can import.  There is also a guide to Unity 5 integration available on Oculus, although be aware that parts of it are now obsolete.

 

Unity VR Samples

 

There is also a pretty significant set of samples illustrating using VR in Unity available on the Unity Store.  Simply create an empty project and import in the example.  These VR Samples illustrate a number of different concepts required for working with VR in Unity.

 

 

In time, more and more functionality should be built into Unity, making this process even easier.

 

Video Version

Programming


30. December 2015

 

This is a tutorial on getting started with Samsung’s GearVRf framework with the Samsung Gear VR.  The GearVR is a virtual reality headset powered by Oculus Rift technology and a modern Samsung android phone.  The GearVRf SDK is a framework made available by Samsung enabling you to develop for the GearVR using Java.  If you are wondering “Hey, can’t you use Unity or Unreal Engine?” yes, yes you can and probably should… but that’s never stopped me from doing things before!

 

First off, there is a guide to getting started available here and it will get you *most* of the way there.  This tutorial covers the missing bits…  There is also a video version available here or embedded below.

 

First off there are a number or pre-requisites before you can begin, you need to have the following installed/configured/registered:

 

The Eclipse requirement is unfortunate, however NDK support was only recently added to Android Studio.  In time expect it to work with Android Studio instead.

 

As part of the installation, make note of where you extract the Oculus SDK.  The Samsung VR SDK has to be installed at the same directory level and I believe requires the folder be named ovr_sdk_mobile.  In other words, if you installed the Oculus Mobile SDK to c:\dev\ovr_sdk_mobile then clone GearVRf to the c:\dev folder. Change into the appropriate folder and run the command:

git clone https://github.com/Samsung/GearVRf.git

This will take a few minutes and download the GearVR SDK.  Now we are ready to start working in Eclipse.  Follow the instructions from Samsung specifically “Build Configuration” to setup Eclipse, then copy the files mentioned in the section “Oculus Mobile SDK”, it’s just 3 jars to 3 different folders that need to be copied.

 

Now we are ready to import the Samsung SDK into Eclipse.  Select File->Import… then Existing Android Code into Workspace.

image

 

Now select the Framework folder ( for example c:\dev\GVRf\Framework if you cloned the sdk into the c:\dev directory ), then click Next.

Go to the menu Project and turn off Build Automatically.  Then in the same menu select Clean… toggle if not already the “Clean all Projects” tick then click OK.  This will now build the SDK.  If you get an error, there is a good chance the your NDK or Android SDK settings in Eclipse are wrong, so start there.

 

Hopefully however everything ran fine.  In which case, let’s start with a sample from the SDK.  In the same workspace you imported and built the framework, import another existing Android project using the same settings, this time importing a project from Sample subdirectory of the GearVRf install folder. 

 

Now that we have a project to run, this next part is CRITICAL or your app will crash on start.  If you haven’t already, go to the Oculus site and register for a signing key ( the link is available above ) and put in the id of your phone.  Instructions are available on the same page as the form on Oculus.  This process will generate and download a file that needs to be included in each application you run.  Simply copy this file into the assets folder of the sample you imported.

 

Now plug in your phone then in Eclipse in Package Explorer, right click the imported demo and select Run As->Android Application. The APK should now be generated and copied to your phone.  However it wont run as you need to insert your device into the GearVR now ( we will address this shortly ).  For now, unplug your phone, run your newly installed app, then insert into the GearVR.  If it loads the main menu, your application crashed.  Ideally your app will now be running. 

 

So that’s it, the steps required to get started with GearVR development using Samsung’s GearVRf SDK.  If you are thinking… Unity/Unreal would be a hell of a lot easier!  You are right… I’ll cover getting started with both of those in the near future.

 

Now that we are running you will quickly notice that putting the device into the GearVR over and over is a pain and requires you to disconnect your device from USB each time making debugging impossible.  Don’t worry, there are two ways around this.

 

Debugging a Samsung Gear VR application

 

Running in Developer Mode ( no headset )

For most builds, you can actually run your code without a device.  This way you can leave it plugged in and remove the time consuming insert in phone and restart process.  First you need to put your phone into developer mode for Oculus.

  • Swipe down and select Settings gear icon
  • Tap Applications
  • Tap Application Manager
  • Locate Gear VR Service, tap
  • Tap Manage Storage
  • Tap VR Service Version Several times
  • Swipe Developer Mode on.  Now you can run without the Rift (great way to record video by the way…)

There is a dedicated post and video on this topic now available here.

 

Debug Wireless

You can also set adb into wireless mode. 

  • On your phone select Settings->Wireless->Click your active connection, make note of your IP address
  • Open a terminal/command prompt and cd into your Android SDK folder\platform-tools
  • Plug in your phone
  • In the terminal/command prompt type adb tcpip 5555
  • Now connect to device wireless with adb connect 123.123.123.123 (<--- obviously, your IP address here)
  • Unplug your device.  At this point you may want to restart Eclipse.
  • Now you can run from Eclipse directly to the device without having to plug in.

 

Video

Programming


29. December 2015

 

So over the holiday I joined the VR revolution with a Samsung GearVR while I wait for the Oculus Rift to be released.  The good news is, it’s really quite cool, except a full review shortly.  However, one of the challenges of reviewing something like the GearVR on the web is taking a screenshot…  How can you demonstrate the experience if you can’t take screen shots?  Well fortunately you can, but it’s a bit of a hack/workaround to get there.

 

First off, you need to have an external keyboard.  Personally I used a Logitech K810 I have sitting around.  Next be sure to pair it with your Galaxy phone, simply select Settings->Bluetooth and locate the keyboard.  Now fire up the GearVR like normal.  Then when running simply hit the Print Screen button on your keyboard and the screenshot will automatically be saved to your photo roll.

 

Now, the screenshot may not look exactly like what you expect.  Here for example is the dashboard:

Screenshot_2015-12-29-15-43-39

Notice the tilting???  Well that’s because I didn’t have my hand on the print screen key when I started the app, so I had to remove the goggles to find the key.  Oops.

 

And here is Netflix running, slightly less tilted:

Screenshot_2015-12-29-15-44-25

 

As you can see, you get a screenshot for each eye and they aren’t square like you’d expect on a PC.  There may be a way to take a screenshot without requiring an external keyboard, but I don’t know what it is.  If you know an easier way, please let me know in the comments below!

General


See More Tutorials on DevGa.me!

Month List