Image Tracking with AR Foundation in Unity

One of the features of AR Foundation in Unity is Image Tracking. It’s one of the “oldest” methods to position virtual elements in the real world.

Is this still relevant today? Of course, it is! Markers are still helpful for the users because you can place them exactly where you want them to be. You can’t do this marker-less yet.

So, do you want to learn how to set up the project to use image tracking for AR?

Setup project πŸ‘¨β€πŸ’»

As with other posts about AR (Face Tracking and Building AR Game), we have to start with the Package Manager and its packages for AR.

You will have to install the following packages: AR Foundation, ARCore XR Plugin (for Android support), and ARKit XR Plugin (for iOS support).

AR packages in Package Manager.

Now we can start working. πŸ€“

Creating Marker

The first thing we should do now is to set up the markers for our project.

To do that, go to the Project window and click Create > XR > Reference Image Library.

Creating Reference Image Library.

Now you have to import an image which you want to use as a marker. Add it to the newly created ReferenceImageLibrary object.

Marker Image setup.

I would also recommend specifying the real-life size of the marker. If you have a print of it, just measure it on the paper.

Measure marker in the real world.

Build AR scene πŸ‘¨β€πŸŽ¨

With every AR scene, we have to start by adding AR Session and AR Session Origin to the scene.

You can do it by going to the Hierarchy window and clicking Create > XR > AR Session and Create > XR > AR Session Origin.

Creating AR Session and AR Session Origin.

Image Tracking πŸ–Ό

When you have both of them, you can add AR Tracked Image Manager to the AR Session Origin game object.

Of course, now we also have to assign the references in it.

AR Tracked Image Manager Component

One reference is for our ReferenceImageLibrary and the second one if for our prefab which will be displayed on the marker. Be aware that 1 unit in Unity space is 1 meter in the real world!

You can also specify how many images you want to track. The maximum number may vary between different devices so I would recommend checking it (read more).

Build settings πŸ› 

Depending on the platform you are using, you may want to change some build settings.

For Android, if your project requires AR support, you have to use at least API Level 24.

Minimum API level for Android.

And for iOS, you will have to use at least iOS 11.0 and check “Require ARKit support“.

Minimum iOS version.

The result πŸ†

And as you make everything correctly, now we can launch our AR app!

AR Cube in the real world!

Great! It’s working! At least for me… πŸ˜…

If you don’t see the object there, your scale may be too big for AR, so try to walk away from the marker. πŸšΆβ€β™‚οΈ

If you find this useful, let me know in the comment section below or share it with your friend! I would really appreciate that! ❀️

And if you are interested in getting emails when I release new post sign up for the newsletter!

You can also check the whole project at my public repository. πŸ”—

See you next time! πŸ€“

Notify of