Unity 3D Augmented Reality(AR) (Vuforia Engine) for Beginners

Cem Yasar
5 min readApr 14, 2019

Hi,

First of all I am also freshman to AR mechanics :)
With Vuforia Engine you can easliy create enjoyable AR applications. It is incrediable AR library.

You should know that not all mobile devices are compatible with Vuforia AR. You can check it here: https://library.vuforia.com/articles/Solution/vuforia-fusion-supported-devices.html

Fortunately Vuforia offers two types of properties that you can test your app with many devices.

As you know that for AR, your application should detect a surface. Then the applications magically creates objects by using this referenced surface. With compatible devices which includes two cameras or depth sensing cameras to measure depth between surface and device. As I mentioned if your device is not compatible, for instance my phone Sony Xperia XA model, you can use Image Target or Ground Plane properties of Vuforia to detect a surface. I suggest using Image Target property, because even with older devices the AR application can detect a surface.

I simply mentioned some key features to eliminate some questions. For example I spent a lot of time to paly with Ground Plane property to detect a surface, then I digged too much to realize Image Target property, and I realized that Image Target property is more suitable for even older mobile devices (such as Android 4.4 versions are very slow). Now I can start to tell what they really are :)

Before I must say I will be using Android device so you must install Android Studio. After installation open Android Studio. It asks to download and install Android SDK. Install it. Then in Unity, in the Edit menu click Preferences. In this menu click External Tools. Here specify Android SDK location. Also you must register to Vuforia site to get developer license. You will be using this license in unity to activate Vuforia. Also for Image Target property you will be using Vuforia Site to turn a background image into a special unity package for surface detection.

You can check this tutorial, it is very helpfull and also I am prepharasing it to be clearer according to my understanding :) https://blog.theknightsofunity.com/unity-vuforia-guide/
Also download this image in this site to be used for Image Target: http://blog.theknightsofunity.com/wp-content/uploads/2016/11/marker_1.png
In this site you can learn how to be registered to Vuforia site and to get a valid developer license.

To enable Vuforia in Unity: Click on Edit menu then Project Settings Menu. In project settings click on Player menu and in Player menu, click XR settings. You can see Vuforia properties here. Enable “Vuforia Augmented Reality Supported” setting by checking it. If you are familier with Unity you must realize that these settings are done with Windows/MAC/Linux standalone enviorenment, Android Environment, WebGL environment seperaretly. Also, for Android settings, in Other Settings you must disable “Android TV Compatibility” property by unchecking. Otherwise, Vuforia causes an error. You can see these environments as tabs in Unity. For our purpose you must also enable Vuforia for Android environment. When you try to enable Vuforia, Unity asks to install some properties. You must install them.

After, you must delete normal camera object in Unity project. Then you must add Vuforia AR Camera into the project. Now you can add Vuforia objects like adding 3D Objects. You see “Vuforia Engine” menu is listed like “3D Object” menu and others are listed in the same menu. You can find them also in main “GameObject “menu.
Select AR camera to look at properties. In the properties you can realize a “Open Vuforia Engine configuration” button. Click on it. You can see license input textbox- “App License Key”. Copy your license key into that textbox. Before including Vuforia Image Target object you must prepare a detectable surface property by using the image, I gave the link above. In Vuforia site you see there are two tabs. License Manager and Target Manager. Click on Target Manager. In this tab you see “Add Database” button. Click it. Simply create a database. After you create a database you see your database name is listed. Click name. It will open a new window. In this windows you see “Add Target” button. Click it. This will open a popup window. Select “Simple Image”. Select your image file. You must write width value of your image. You can check the value in your computer. Name it, then click “Add” button. Vuforia creates a unity package. Download it and import it to the Unity. You can learn details by google easliy.

After downloading unity package, in Unity, add Vuforia “Image Target” object into the project. You will see in the properties that there is “Image Target Behaviour (Script)”. In this script you set your custom database and image properties. In the “Image Target” you can add a 3D Cube object or others which you want. By doing so when Vuforia detects your surface it will show your objects which are in the “Image Target”. Also you can manupulate “Default Trackable Event Handler (Script)” by extending it. Then you will disable original script, add new script as component. You can set public objects which are passed as parameters. In this script you can write codes in the “protected virtual void OnTrackingFound()” method. You can create objects manually.

Adding “Image Target” object is not enough, you must also add Vuforia “Plane Finder” object from Vuforia Engine->Ground Plane->Plane Finder in the GameObjects main menu or right-click context menu. Then, in the properties, find “Plane Finder Behaviour (Script)”. Here, you must specify your “Image Target” in the “Plane Indicatior” attribute.

We have done the main part. The rest are imaginations :) Creating objects by taping on to the screen, creating collisions…

You can build Android package in the Build Settings, then copy the apk file into your device and install it (you can also cope with ADB settings but I really do not like it). You print your surface image in A4 file. Open your app and try to focus on this image. The app will detect it as a surface, then your objects, like cube, are created on it :)
You can also test by using your device as a remote camera. By using DroidCamera application you can use your device as an IP camera in local network. Also you must install client app to connect to your deivce from your computer. Then, in Vuforia AR camera settings (by clicking “Open Vuforia Engine configuration” button). Vuforia will list DroidCamera, select it. Without installation, you can test your app immediately by clicking play button in Unity.

I hope you will be doing good :)

Cem Yaşar

--

--