Unity AR

AR projects allow you to show content by pointing your camera onto an image or a 3D object that will act as an anchor point for your 2D/3D to be displayed on top of.

Image target AR tutorial

Image target AR tutorial

AR with Unity - Step #1 - Development environment setup

Please notice that this is the first of a series of tutorials progressing from basic concepts to more functional and complex projects.

Aims

This tutorial aims to get you started creating AR applications using Unity and the Vuforia plug-in.

Prerequisites

  1. Download and install Unity 2019.2.0f1.
    Previous versions might also work, however, this tutorial was made using Unity 2019.2.0f1 (please read instructions below before installing Unity).

  2. Create a Unity personal account. To use Unity you will have to create your own account as you will be prompted to login when you start running the software.

About the Vuforia Engine

As of 2017.2, Unity integrates the Vuforia Engine, this SDK allows you to easily create AR applications that you can deploy on both Android and IOS devices.

Android and/or IOS build support

To compile mobile applications on your computer, you will need to make sure to download the Android and/or the IOS build support. Please be aware that both Windows and IOS computers might allow you to compile Android apps, however, IOS apps require you to use a MAC computer running Xcode as IOS build is not supported on Windows PCs.

Please keep in mind that in most cases you won't need both Android and IOS build support, think about the kind of device are you planning to use to test/show your project. We found that in most cases, students use just one device. Also, keep in mind that building an app for two different platforms might add significant complexity to your project as you might need to test/debug your app on both platforms.



AR-vuforia-setup1-f.png

When installing either of these SDKs you might find your self facing three different scenarios, first, you might be installing 2019.2.0.f1 for the first time, second, you might have Unity already installed on your computer and you are missing the SDKs, finally, you might have a previous version installed on your computer, it does not have the SDK installed and, for some reason, you can't install Unity 2019.2.0f1, all these situations require different procedures that will be explained in the following lines.

Scenario #1 - Installing Unity 2019.2.0f1 for the first time

First, we recommend installing the Unity HUB as it will make your life a lot easier when installing and using Unity 2019.2.0f1. After installing the HUB, you just need to go to visit the Unity Download Archive, find the Unity 2019.2.0f1 version and click on the button that says "Unity HUB" this will automatically open the HUB and then run the installation wizard.

AR-vuforia-setup1-c-1.png

AR-vuforia-setup1-c-2.png

You will see a list of all the available Unity components, you just need to make sure that the Android and/or the IOS build support is selected before continuing with the installation. AR-vuforia-setup1-b.png

Do notice that the Android build support includes the Software Development Kit (SDK), the Native Development Kit (NDK) and the Java Development Kit (OpenJDK). Just make sure all of them are selected before continuing. After this, you just need to follow the final steps of the installation process.

Scenario #2 - Installing Android and/or IOS build support for a previously installed copy of Unity 2019.2.0f1

Your previous copy of Unity 2019.2.0f1 must have been installed through the Unity HUB, if you don't have Unity HUB installed then we recommend uninstalling your previous copy of Unity and following the steps for the Scenario #1. To add the Android and/or the IOS build support to your previously installed copy of Unity you just need to open the Unity HUB and click on the installs link, then click on the three dots found on the top right corner of the Unity 2019.2b box.



AR-vuforia-setup1-0.png

This will display a menu that includes the "Add modules" option, once you click on it, you will see a list of components you can add to your previously installed copy of Unity.

AR-vuforia-setup2-a.png

AR-vuforia-setup3.PNG
After this, you just need to follow the final steps of the installation process.

Scenario #3 - Installing Android and/or IOS build support for a previously installed older version of Unity

Please be aware that the Unity HUB might allow you to install more than one version of Unity, however, the "Add modules" option might not be available for other Unity versions.

AR-vuforia-setup2-c.png

AR-vuforia-setup2-b.png

If for some reason you have to use an older version of Unity on your computer and it is missing the Android and/or IOS build support, you will have to visit the Unity download archive, locate your version of Unity and download the Unity installer. AR-vuforia-setup1-c.png

After running the installer, you will get a list of components, do make sure to untick the box next to the Unity editor (first item) otherwise you will reinstall it, select the desired build support and follow all the installation steps. AR-vuforia-setup1-D.png

AR-vuforia-setup1-e.png

Please use old Unity versions as a last resort as configuring the development environment might require following more complex procedures and downloading extra components.

Next step - Adding content to your project

In the next step, we will create a free Vuforia developer account, generate a license key and create a target database using your own content.

Go to step #2 - Unity project setup

Image target AR tutorial

AR with Unity - Step #2 - Unity project setup

Please notice that this is part of a series of tutorials progressing from basic concepts to more functional and complex projects.

Aims

This tutorial aims to help you setting up a AR Unity project using the Vuforia plug-in.

Prerequisites

  1. Developing environment setup.
    In order to continue with this project you should make sure to first check our tutorial:
    AR with Unity - Step #1 - Developmen environment setup

Understanding Image target AR.

You can use Vuforia to create different types of Augmented Reality projects, in this tutorial, we will be focusing on the creation of an Image target AR project, this means, creating a mobile app that will look for and track a printed image that will act both as a trigger and a spatial reference for your content to be displayed on top of.

AR-vuforia-basics1.png

In order to set up your Unity project you will need four different items, the first two: a camera and image object will be available inside of Unity once we enable the Vuforia plugin, the other two: a license key and a target database will be generated in the Vuforia developer webpage (step #3 of this tutorial).

AR-vuforia-basics2.png

Enabling the Vuforia plugin



Enabling the Vuforia plug-in (already included in Unity 2019.2.0f1) is a quite straight forward process, first, let's create a new Unity project, please make sure you select a 3D template. Unity-SteamVR-Setup-4.PNG

Now let's check the "gameObject" menu as this is were you will find the Vuforia elements once you enable the plug-in, for now, you will notice Vuforia objects are missing.

AR-vuforia-setup5-1.png

To enable the plug-in, we need change the player's settings on the project settings panel, the easiest way to do it is by opening the build settings panel found in the File menu and then clicking the "Player settings" button found on the left bottom corner, finally, you will need to tick the "Vuforia Augmented Reality Supported" box found inside the XR settings section.

AR-vuforia-setup5-4.png

This will install the Vuforia package, once the process finishes, you will be able to find and access the Vuforia objects collection through the GameObject menu.

AR-vuforia-setup5-5.png

Adding Vuforia objects to your project

With the Vuforia plug-in enabled in your project, right-click on top of the hierarchy panel and place the cursor on top of the Vuforia Engine submenu and then click on top of the AR Camera option. This will add a camera object to your scene.

AR-vuforia-setup13-a.png

Now, with the Vuforia camera selected, let's take a look in the inspector. Down at the bottom, you will find the Vuforia Behaviour script component.

AR-vuforia-setup13-d.png

If you click on top of the "Open Vuforia Engine Configuration" button, you will be able to access the panel where you should paste your License Key and add your target database, we will come back to this panel later on.

AR-vuforia-setup13-e.png

Now, let's add the image target object, this is the game object that will hold all the information related to the target image you are going to use as a trigger for your content. Again, right-click on top of the Hierarchy panel, select the Vuforia Engine submenu and this time, click on top of the Image option, this will add an image target object to your scene.

AR-vuforia-setup13-b.png

Please note that if you are adding an image object to your project for the first time, Unity will ask you if you want to include a default database, please click the "Import" button, this will automatically insert a default image as a texture for your image object. importing this default database will be useful for you to understand how Vuforia works and won't interfere with the future development of your project.

AR-vuforia-setup13-c.png

If you take a look inside of the Scene panel (element #1 on the image below), you will notice a plane with an image applied as a texture (see element #2), this is the digital image that your mobile app is going to compare to your physical print in order to trigger your content. Now, if you look in the Inspector (see element #3), you will see a reference to both a database and an image target, this is the example content you have just imported. Once you insert your custom content, we will come back to this panel to replace the sample content.

AR-vuforia-setup13-f.png

Next step - Adding content to your project

In the next step, we will create a free Vuforia developer account, generate a license key and create a target database with your content.

Go to step #3 - adding content to your project

Image target AR tutorial

AR with Unity - Step #3 - Adding content to your project

Please notice that this is part of a series of tutorials progressing from basic concepts to more functional and complex projects.

Aims

This tutorial aims to help you set up a AR Unity project using the Vuforia plug-in. In this step, we are going to review all the components needed to build a AR app.

Prerequisites

  1. Previous steps.
    To continue with this project you should make sure to first check our previous AR tutorials:

    AR with Unity - Step #1 - Development environment setup

    AR with Unity - Step #2 - Enabling the Vuforia plug-in

Creating your Vuforia account



To add your content, first you will need to create a Vuforia account, this will allow you to get a free Vuforia license key and also to create an image target database. First, visit the https://developer.vuforia.com/ website and click on the register button, it will display an online form to register as a Vuforia developer.

AR-vuforia-setup11.png

Generate a license key



After creating your account, you should be able to access the license creation section by clicking the "Get Development Key" button.

AR-vuforia-setup12.png

We suggest putting a meaningful name to your license, please notice that you can use a single free license for multiple projects, however, you could also have different licenses for different reasons that are not going to be explored in this tutorial.

AR-vuforia-setup13.png

Once you hit the "Confirm" button you should be able to see it displayed in the License Manager, please click over it to access the license key and check the included features.

AR-vuforia-setup12-a.png

Now click over the license key code to copy it to your clipboard.

AR-vuforia-setup13.png

Back in Unity, please select the Vuforia camera and press the "Open Vuforia Engine Configuration" button in the Inspector and paste your License Key inside of the License key field.

AR-vuforia-setup13-g.png

AR-vuforia-setup13-h.png

Creating an image target database



Before starting, it is worth taking a moment to understand Vuforia databases, a Vuforia database contains both the image and tracking points data used to create a target. To create an image target, you will need to upload an image (JPG or PNG images in RGB or grayscale and less than 2MB in size ) to the Vuforia website and it will rate it (from 0 to 5 stars) based on the amount of "trackable features", more features means higher rating.

A feature is a sharp, spiked, chiselled detail in the image, such as the ones present in textured objects. The image analyzer represents features as small yellow crosses. Increase the number of these details in your image, and verify that the details create a non-repeating pattern.

To give you an example, we have previously uploaded two different images to the Vuforia target manager and these are the results.
AR-vuforia-basics3.jpg
AR-vuforia-basics4.jpg
Now let's switch back to the Vuforia developer webpage to create our database. Click on the "Target Manager" tab and then click on the "Add database" button.
AR-vuforia-setup14.png

We suggest also putting a meaningful name to your target database. Do make sure that Type is set to Device, this means that all the data will be stored in the device where the AR app is running rather than downloaded from the cloud.

AR-vuforia-setup15.png

Once created, your database should be available in the Target manager. To upload your image target please click on top of your database.

AR-vuforia-setup15-a.png

Once in your database page, do click on top of the "Add target" button.

AR-vuforia-setup15-b.png

This will display a web form that will guide you through the process, please make sure that Type is set to Single Image, also, be aware that your image size should match the exact size of your printed image to avoid scale mismatch. Unity uses meters as the default unit scale so if your image width is 50cm you should type 0.5

AR-vuforia-setup16.png Usually, it doesn't take long for your image to upload and get rated, be patient, if it does not refresh automatically, just click on top of the rating link, that should be enough to refresh the rating without refreshing the page.

AR-vuforia-setup16-a.png

AR-vuforia-setup16-b.png Now, select your database and click the "Download database" button, before hitting "Download" please do make sure Unity Editor is the chosen development platform. AR-vuforia-setup24.png After downloading your database, check that your Unity project is open and then double click on the database file then Unity will then display a Window with all your database elements, you should click the "import". After this is done, please select the image object and then look in the inspector, you should be able to replace the sample database with the one you have just imported. AR-vuforia-gif1.gif Now let's add a 3D model to the project, for this tutorial we are going to add one cube but you are welcome to use your 3D asset instead. We will need to scale it down as the default size is a bit big, For the object to be displayed, you will need to make sure you make it a child of the image target object. AR-vuforia-gif2.gif

Next step - Building your app and testing it

In the next step, we will build the app file and will test it on and android phone.

Go to step #4 - Building and testing your app (Android)

Image target AR tutorial

AR with Unity - Step #4 - Building and testing your app

Please notice that this is part of a series of tutorials progressing from basic concepts to more functional and complex projects.

Aims

This tutorial aims to help you set up an AR Unity project using the Vuforia plug-in. In this step, we are going to review all the components needed to build an AR app.

Prerequisites

  1. Previous steps.
    To continue with this project you should make sure to first check our previous AR tutorials:

    AR with Unity - Step #1 - Development environment setup

    AR with Unity - Step #2 - Enabling the Vuforia plug-in

    AR with Unity - Step #3 - Adding content to your project

Building your project

Before building the app we need to make sure we disable the default main camera as there can't be two cameras in your project, to do so, just select it and untick the box next to the camera name field in the inspector.

AR-vuforia-gif2-a.gif

To build your app first open the file menu and select Build settings, please make sure that your build platform is set to Android, in this example, we will switch the build platform from Windows to Android, first, we select the Android build and then click the "Switch Platform" button. It should update after a few moments. Next we need to press the "Add open scenes" button to make sure our scene is added to the build, finally, just click Build and select a folder and put a name to your project.

AR-vuforia-gif3.gif