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! ?

4 8 votes
Article Rating
Subscribe
Notify of
guest
24 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
rabishan
rabishan
4 years ago

hi. thanks for the tutorial. is it possible to keep tracking the image after object is spawned?

Cairy
Cairy
4 years ago

Hello,
thanks for the great tut.
Is it possible to add different objects and different images in the same project?
The flowe image shows a 3D flower, the dog image shows a 3D dog and so on.
Thanks in advance.

petur
petur
Reply to  Patryk Galach
4 years ago

it seems not to work, can you help a litle

Karina
Karina
Reply to  Patryk Galach
4 years ago

this dose not work for me

Alessandro Luz
Alessandro Luz
Reply to  Patryk Galach
3 years ago

Doesn’t work, this component is a singleton, you can only have one per scene. If you know how to do it let us know please

Kirill Kuzyk
Kirill Kuzyk
4 years ago

Thanks for the tutorial!
If someone is looking for a way to test Image Tracking in Unity Editor, I made a plugin that supports this.
https://forum.unity.com/threads/ar-foundation-editor-remote-test-and-debug-your-ar-project-in-the-editor.898433/page-2#post-5986280

Aske
Aske
4 years ago

Thank you for the tutorial 🙂
I followed the tutorial, but both on iOS and Android, the camera feed isn’t showing. Any idea of why that may be?
I’m using Unity 2019.4.1f

Laskarin
Laskarin
4 years ago

Where is “AR Tracked Image Manager”? It doesn’t seem to exist in my project or links.

Daniel Laskarin
Daniel Laskarin
Reply to  Patryk Galach
4 years ago

The project platform is set to Android (it was by default set to “PC, Mac & Linux Standalone), and yes AR Foundation, ARCore XR Plugin, and ARKit XR Plugin are all installed.

Daniel Laskarin
Daniel Laskarin
Reply to  Patryk Galach
4 years ago

Yeah, thanks. Somehow the Android SDK didn’t come along when I did a Unity update. Had to delete Unity, UnityHub, registry entries, …. royal pain in the whatname. got it now.

Daniel Laskarin
Daniel Laskarin
Reply to  Patryk Galach
4 years ago

Actually, I thought it was solved, but no. So, where do I find “AR Tracked Image Manager”?

petur
petur
4 years ago

if you can help me to set up scean
I have 10 prefabs I want to be triggered from 10 different images.

Anthony
Anthony
4 years ago

Hi all, Thanks for the tutorial. I managed to create an application based on ARFoundation and Image tracking and it works well. I could notice that the camera pose is computed/given in the AR session coordinate system (the origin being the position of the camera when the AR session started). But I’d like to be able to get the camera pose with respect to the tracked image i.e. expressed in a coordinate system based on the image. For that, I need to get the image position expressed in the AR session coordinate system but I could see it is given… Read more »

RamoramaInteractive
RamoramaInteractive
3 years ago

Is it possible to add a Collision Detection to the Game Object on the tracked image? I want to create a sword fight simulation. For example: On a card I track a sword and if I hit another object, which was not tracked on an image, this object should turn to the color red.

How Canada you do it?

Pascal
Pascal
3 years ago

Impossible de build.
UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor
Malgré avoir suivit scrupuleusement le tuto :/ …

Yogesh Nalam
Yogesh Nalam
2 years ago

Hi. Thanks for the tutorial. But my image(imported as .obj and converted to Prefab) doesnot get fixed to the tracked image. Even if I move, away my prefab comes along with the camera. But is works for inbuilt object like Cube, Sphere. Can you please help out.

ILIAS
ILIAS
2 years ago

Hi, thanks for the tutorial.
I have a problem. I’m trying to connect my Samsung S21 using Unity Remote 5 app, to test my project. But I saw in my mobile screen the background and not the camera view. So I cannot Image Track the marker.
I check the Android SDK, Google USB Driver, Android devices in the project.
I dont know what else to do. Have you any idea what to check? Thank you.

xristis
xristis
2 years ago

hello,the object when I move away from the marker moves, do you know why this can happen?

24
0
Would love your thoughts, please comment.x
()
x