Using AR anchors in Unity AR foundation

In continuation to our AR tutorial series today we are going to see how to use Anchors to keep your objects in place in the real world. If you are totally new to AR, check out our other tutorial on

  1. Getting started with Unity AR foundation.
  2. Object placement in AR.
  3. AR light estimation.

What are AR anchors?

AR anchors are components of Unity AR foundation that lets you fix the position of an object relative to other feature points in the real world.

For example, if you want a cloud at a height of 1 meter from the surface you can place an AR anchor there and spawn the cloud at that point. Now even if you move around the cloud will remain at that position.

An important point to note is AR anchors are performance expensive. A lot of computation goes into keeping the anchors in place. You must try to limit the number of Anchors you use to reduce the computational load.

How to place AR anchors?

You can either add an AR anchor to an existing gameobject or spawn a prefab with AR anchor component.

Before adding the AR anchor component, you need to add the AR Achor Manager to the AR Session Origin.

AR anchor Manager.

AR anchors won’t work without features points like planes. So, you need to detect at least one plane for the AR Anchors to work.

To add AR anchors to the prefab, select the prefab and click on Add component. Search for ARAnchor and click add.

AR anchor component in the inspector window

To add AR anchors during runtime using code., use the code below.

Gameobject.AddComponent<ARAnchor>();

Things to know about AR anchors

  1. AR anchors are performance expensive. Your FPS will drop if more Anchors are present in the scene.
  2. AR anchors won’t work without feature points like plane. You can disable plane detection after a few planes have been found if you don’t need them.
  3. You should not change the transform of the AR anchor. Unity foundation takes care of it. If you need to change the transform of an object with AR anchor then destroy the Anchor component, move the object and add the AR anchor back.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from VionixStudio

Subscribe now to keep reading and get access to the full archive.

Continue reading