Create your first AR application with Unity and Vuforia - ITgenerator

Free e-book! "The complete guide on how to avoid mistakes in creating mobile apps" DOWNLOAD NOW

Create your first AR application with Unity and Vuforia

Tomek Antkowiak

01/22/2018 6 min read

Unity-euphoria

Augmented Reality (AR) is here to stay in the mobile app market, and its popularity is still growing. Games like Pokemon GO revealed the potential for commercial success of this technology. In this tutorial, I’m gonna show you how easily you can start making your own AR apps with Unity and Vuforia.

VUFORIA
Vuforia is a Software Development Kit (SDK) for creating AR apps. It uses Computer Vision to track images and 3D objects in real time. This allows putting virtual 3D objects in relation to real-world objects on the camera screen.

Vuforia is not open source, but it has a free version and the price of the full version is reasonable.

WHAT YOU’LL NEED
In this tutorial, we will create an Android app that will recognize an image in the real world and display its 3D model.

To make it you will need:

-> Unity

-> Android SDK

-> Vuforia (you can install it with Unity or download an importable package from Vuforia site)

So let’s get to work and have fun 🙂

CREATING A PROJECT IN UNITY
Create a new project in Unity. Now you have to set build configuration of Unity so that it will build for Android platform. Go to File->Build Settings, choose Android and press Switch Platform.

Next, we have to set other build settings required by Android apps, for example, package name, icon, minimum SDK version etc. To do this, press Player Settings… button in the Build Settings window. In the new section in Unity inspector we have to set 3 parameters:

-> Company Name — it’s the name of the developer

-> Product Name — it’s the name of your app

-> Package Name — it’s the name of Java package. It will be used for identifying your app, a standard package looks as follow: com.companyname.productname

That is all regarding the configuration of the project. We can handle Vuforia now.

WORKING WITH VUFORIA
Sign up for Vuforia developer platform

Go to Develop tab and press Get Development Key button. Create a new project and when it appears on the list, go into project details. You have to copy the license key of the app. It is required by Vuforia to work.

Next, in the Develop tab, go to the Target Manager subtab. There you can create a database of objects that Vuforia will be able to recognize. There are 3 types of databases: Device, Cloud, VuMark. We want the Device option (it is the only possible option in the free version of Vuforia) and you will be able to download it and import it into Unity.

When our database is set up, we have to go into its details. We have to add a new target. A target is an object that Vuforia will recognize and work with. There are 4 types of targets:

Single Image (that is our pick), Cuboid, Cylinder, 3D Object.

Next, we have to upload an image file, input its width and name it.

After adding the target, it will appear on the target list. It is worth to pay attention to the ranking of targets. The higher, the better. It means that an image or object with higher ranking has more specific points (features) for Vuforia to recognize it. In my case, the 9 of clubs card has the highest possible ranking (you can even check features in target details).

When we add all of our targets, we choose which ones we want to have in our Unity package. After this, we press the Download Database button. We must choose Unity Editor as a development platform. Thanks to that the file will be importable to our engine.

The process of working with Vuforia is now done. We can go to Unity, where we will make use of the Vuforia magic.

USING VUFORIA IN UNITY
We have to import our database to the Unity project. We can do this by choosing Assets->Import package->Custom package and picking our file.

If you don’t install Vuforia with Unity you have to import this file (Unity Extension). You can import it in the same way as the database.

For our app to have some kind of sense we have to have a 3D model to show to the user. You can download it for free from Unity Asset Store. You can go there by choosing Window->Asset Store from Unity menu.

Now we have all ingredients to make our app.

To work Vuforia uses a special camera object called ARCamera. We have to delete the standard Unity camera and then, from our assets, we must choose ARCamera and place it on the scene. It can be found in the Vuforia Prefabs folder. Set the position of it to 0,0,0 and go to Vuforia configuration.

You have to add the license key in Vuforia configuration.

If our app wants to recognize objects in the real world, we have to add these objects to the scene. An object that represents a Single Image is called an Image Target. You can find Image Targets in the Vuforia Prefabs folder. After adding it to the scene set its position to 0,-50,0 and in the Image Target Behaviour script of this object set a database to our database and image target to the corresponding element. From now on Vuforia will recognize our image in the real world.

The last thing to do is to add a 3D model as a child object of the Image Target and set its position to 0,0,0. Now go back to Vuforia Configuration, set Dataset for our database and activate it.

And that’ all. Now you have to simply build a project into apk file and install it on an Android device. To do this go to File->Build Settings and press Build button. In the app all you have to do is point your camera to the chosen image and your model will appear.

RESULT
In the end, we have an app that can track an object in real life to show a 3D model with animation.

I hope that this tutorial was has been easy to follow, it’s showing you that creating AR apps isn’t hard and it has boosted your creativity to make interesting apps using AR.

The whole project is available on GitHub here

Rate this post:
Create your first AR application with Unity and Vuforia
5 (100%) 2 votes

Tomek Antkowiak
Android Developer, specialized in Java & Kotlin programming languages, with the knowledge of a few main game engines such as Unity, Play Canvas or Cocos2D.

The complete guide on how to avoid mistakes in creating mobile apps

Ebook - The complete guide on how to avoid mistakes in creating mobile apps

Retrain neural network models optimized for mobile to recognise custom objects using TensorFlow

For Developers

Retrain neural network models optimized for mobile to recognise custom objects using TensorFlow

INTRODUCTION Machine learning in applications becomes more and more popular. Intelligent YouTube or Netflix recommendations, live text translation by Google Translate. Combining the power of mobile, artificial intelligence and machine...

Keep reading

Join our
tech-driven
community!

Subscribe

Back

Shape your future
with the great team