Augmented Reality Kit: Quick Start Guide

Augmented Reality is an exciting new way to develop games and apps that support the use of 3d objects in real world space. If you've ever played Pokemon Go then you're familiar with what Augmented Reality (AR) is. Other popular apps have been sprouting up to take use of AR capabilities for more practical purposes such as Ikea's catalog, pick your furniture and see how it looks in your place. Regardless of how you use AR for development there are three main resources we can use to develop for various AR capable hardware.


ARCore

ARCore is created by Google and is used for Android devices. You can read more about the requirements needed to use ARCore and what it is capable of. The features of ARCore are nearly identical to those used for iOS.

Vuforia

Vuforia by PTC Inc

Vuforia has been around for quite some time now and is quite robust. One of the great benefits of using Vuforia is that it can be used on Android and iOS devices. It can also be used with a variety of other AR enabled devices which you can read about here: https://www.vuforia.com/devices.html

ARKit

ARKit by Apple

AR Kit is what we'll be using for this article. It's only available for iOS devices and requires the use of Xcode which also means that you'll need OSX to build AR apps with ARKit. 


Getting Started with Unity ARKit

In this article I'll go over the basic steps needed to get started with developing a simple AR scene in Unity with an iPhone. To follow along with this article you'll need four things:

  • Unity 2017 or above
  • iPhone with iOS 11+
  • Xcode 9+
  • Apple Account (free account can be used)
  • Unity AR Kit plugin
To start you'll want to create a new project then import the Unity AR Kit asset into your project. You'll find a variety of different scenes and files in this asset. This asset contains a number of example scenes you can test out. To avoid confusion and to make things simple, we'll create a scene from scratch and just include what we need. 


Create a new scene if you haven't already by going to File > New Scene

You can populate this scene with your own 3d models, but for this article I'll be using the Kyle Robot from the Unity Asset Store.


Drag this into your scene at a position of (0,0,3) for the Transform position, you can also rotate him to face the camera



We'll need to add a few scripts to our Main Camera, these will be the Unity AR Video and the Unity AR Camera Near Far. Assign the YUVMaterial to the Unity AR Video script


Next create an empty game object and name it AR Camera Manager and add the Unity AR Camera Manager script. 
Assign the Main Camera to the Camera slot


Lets also change the Clear Flags setting to Depth Only so we don't render a skybox with our environment.

Building an AR App

Save your scene and call it AR_Demo and add this to your Build Settings (add open scenes or drag into "Scenes in Build")

We're still using the default platform of PC, Mac and Linux Standalone. We need to switch our platform to iOS. Select iOS and press Switch Platform at the bottom.


Lets just into the Player Settings at the bottom of the Build Settings window. You can also find this from Edit > Project Settings > Player. From here you'll need to go into Other Settings to change the Bundle Identifier to com.ardemo.test


Scroll down a bit further and locate the Target minimum iOS Version and change it to say 11 (use the latest version)

You are done with the player settings, go back to your build settings so that we can build our app.

From here we have a few options, we can click Build or Build and Run. By using Build, we'll build a version of this app that we can then continue to build within Xcode. With Build and Run we'll build the game then attempt to automatically continue the process by opening up Xcode for you. Either process will result in the same end process which is to open the project in Xcode. To make this easier to understand we'll just do this manually by clicking Build.

Click Build then save this on your Desktop to make it easier to locate later. Once you have finished the build you'll need to locate where the folder is located and open it up

From here you'll need to locate the Unity-iPhone.xcodeproj, you'll need the latest version of Xcode to follow along with this. 
*Xcode 9+ is needed to work with ARKit. 

Double Click this file to open it up in Xcode, you should see this with the project selected on the left side


At this point you want to ensure your iOS device is connected, for this demonstration I'm using an iPhone SE. At the top you can select the device you want to build to


From here you'll need to review the information displayed in the center of the screenshot above. Most notably is the Bundle Identifier and Deployment Target which should be com.ardemo.test and 11.0

You'll also need to assign a Team, this is where you'll utilize your Apple account. If this is your first time you'll need to add an account and proceed with the prompts given. If you experience issues with your bundle identifier not being usable with your account you can change the name of it as I had to here



From here you're ready to build your app with Xcode. Double check that your iOS device is connected and unlocked. This process could take a few minutes. When it completes it'll automatically start the app on your iOS device. 

If your app gets blocked due to your iOS security setting you can enable it through General > Device Management

End Result

If everything went as expected you should see your app working, you'll need to give permission to use your camera for this to work. Below is what you should expect to see from this app. Below that is another example of using a scene from Eat Sheep. 







  • killzone

    I wonder how to do that on Android... ;) :D

  • Ronald Vermeij

    Great article Jonathan, is this also do-able with Blender and an AR platform?

  • crew
    Jonathan Gonzalez

    killzone Once I'm able to get a ARCore capable device I'll go over the process for the Android side as well. The process should be fairly similar.

  • crew
    Jonathan Gonzalez

    iindigowarrior9 I'm not aware of how this would work with Blender. This was made using Unity and ARKit. You could also use this directly with Xcode alone. The models shown (sheep and farm) were created in Blender, but outside of that I didn't use Blender.

  • Ronald Vermeij

    jgonzalez Thank you Jonathan.

  • killzone

    Thank you and awesome stuff Jonathan... I would pretty much appreciate that... AR seems like something really fun to do... Is it only possible to use animation loops? Cheers...

  • crew
    Jonathan Gonzalez

    killzone I'm not sure what you mean by animation loops. The gifs are posted loop, but that's not what AR is used for. I just used it to demonstrate how it works.

  • killzone

    jgonzalez When I look at the sheep it seems like there the head is in a constant loop animation... I know AR is used to look through a camera device of sort to see virtual items like characters and buildings... and you can walk around them and things like that... but can you for example make a movie in AR and watch it... if that makes sense...

  • killzone

    O... K.... NVM... I just searched online... GIYF after all :D.... Alright I am really looking forward to the android version Mr. Gonzalez Sir ;)

  • LJ Simpson

    Awesome article Jonathan! Thanks for posting.

  • crew
    Jonathan Gonzalez

    ljsstudio Glad you liked it!