In this post, you'll learn how to integrate the Vuforia SDK into a Unity project. It should not take more than 15 minutes to complete this tutorial.
Vuforia has a simple structured licensing scheme. Any app that’s currently in development can get a free license key- including indie devs and enterprises. This means there’s a low initial cost of acquisition and anyone can start developing AR games with Vuforia.
Once your game is ready for release, Vuforia has various licensing tiers, each reasonably priced. However, take note that Vuforia has a specific licensing and pricing schemes for physical AR-enabled products like toys.
Currently, Vuforia offers direct support for the Unity engine by supplying their SDK in a native package that can be downloaded directly from their web site, at the following link.
The package includes several prefabs and scripts that simplify the initial integration of the Vuforia SDK into a Unity project. At the moment of this writing, there’s no confirmation that Vuforia will offer the equivalent for the Unreal engine.
The initial learning curve of Vuforia’s SDK is very smooth, most of the complexity of Vuforia’s core technology is well abstracted but still configurable that you can easily customize it to your own specifications.
Step 1: Register
To use Vuforia’s SDK, you need to first register on their official developer website so you can manage your licenses and image targets, also known as markers.
Step 2: Get a license
Once you have a Vuforia developer account setup, go to the License Manager page. Even if you are still in the development stage of your project, you need to generate a license.
Click on the Add License Key, choose Development under Project Type, and enter your App Name. Select Mobile as your Device.
After pressing Next, don’t forget to accept the Terms and Conditions and Confirm.
Step 3: Download the Unity SDK
Once you have finished generating your license, you will need to download the official Vuforia SDK for Unity package on their Download page.
Step 4: Import the SDK in Unity
If you don’t have a Unity project already setup, create a new one. Once the editor is loaded up, double-click on the Unity package you downloaded from Vuforia site.
Click import and all the necessary Vuforia files will be added to your project.
Step 5: Add an AR camera to the scene
The most important prefab that’s included in the Unity package on the Vuforia site is the ARCamera. It contains everything you need to build your augmented reality scene.
In Unity, create a new scene and then drag in the scene the ARCamera prefab that’s in the folder Vuforia -> Prefabs.
Step 6: Configuring the AR camera
The ARCamera prefab will not function without a valid license. You should see in the inspector list of the ARCamera prefab, an attached component named “Vuforia Behaviour (Script)”, in its parameters listing, there’s a textbox just beside “App License Key”. Simply copy and paste the license you generated earlier on the Vuforia site.
Step 7: Choosing the right image target
The image target is the main ingredient that will make or break your AR project. To help guarantee that Vuforia’s computer vision implementations will be able to easily detect and track your target image when scanning an environment with the device’s camera. Choose an image that has very distinct features.
For more information on this subject, please read the article “Attributes of an Ideal Image Target” in Vuforia’s official documentation.
You will need to download and print the following file which you be using as a image target.
By Frederic S. Remington (Photograph of original painting) [Public domain], via Wikimedia Commons
Step 8: Setting up the image target database
You will need to go on the Target Manager page on the Vuforia site and select Add Database. You will need to give a
unique name to your new database and choose the Device as the type.
Select your new database and select Add Target. Choose Single Image as the type. Browse and select the image target you just downloaded. For the width, you can enter “1” and give your new image target a unique name.
After pressing Add, you should see your new image target is being processes and will receive a rating which will indicate how recognizable it will be to Vuforia.
Once your new target image has been processed, click on the Download Database button. Select the Unity Editor as the development platform and then press Download.
You will notice that a Unity package will be generated. You simply need to import it in your current project.
Step 9: Setup your new Database in Unity
Click on the ARCamera object in your scene’s hierarchy, under the Database Load Behaviour, select Load Data Set to “Your Database Name”, then tick on the Activate button.
Step 10: Setup your Image Target in Unity
Select an ImageTarget prefab under the folder Vuforia-> Prefabs and drag it into your scene’s hierarchy.
You should see under the Inspector list of the ImageTarget prefab, a component named “Image Target Behaviour”. Select your new database in the list that’s besides the Database label.
Set the width to 10 and you should see your image target in the scene view.
Step 11: Add a 3D object on your mark
Now, you will need to add a 3D object that will be rendered when the image target is recognized. You can use any mesh, even one that’s already animated. As a test, you can create a primitive by selecting GameObject -> 3D Object -> Sphere.
Make sure it floats over your target image in the scene and in the hierarchy. Drag the new Sphere object under ImageTarget so it becomes a child.
Any mesh that’s a child of the ImageTarget object will be automatically rendered when the device’s camera recognizes and locks on the image target in real space.
Step 12: Testing
To test your new AR-enabled scene, you will need a web cam. Simply hit play and take your printed target image and make sure your web cam can see it. You should now see in the camera’s video output, a sphere floating over your target image.