ImageTracking ARTrackablesChangedEventArgs<ARTrackedImage> Removed

Hello everyone, we have the following code to track the images. But the “removed” event is never called. I would like to undestand better it’s behaviour. Removed mean when is removed from the library or when is not on the camera?

void OnChanged(ARTrackablesChangedEventArgs<ARTrackedImage> eventArgs)
{
    foreach (var newImage in eventArgs.added)
    {
        // Handle added event
        HandleImageFound(newImage);
        //Debug.Log("added image");
    }

    foreach (var updatedImage in eventArgs.updated)
    {
        // Handle updated event
        HandleImageUpdated(updatedImage);
        //Debug.Log("updated image");
    }

    foreach (var removedImage in eventArgs.removed)
    {
        // Handle removed event
        HandleImageLost(removedImage.Value);
        
    }
}

Thanks in advance,
Simone

I collected some knowledge while developing Business Card — my Asset with Multiple Image Tracking.

ARCore (Android) Behavior

ARCore Requirements: Supported Devices & Augmented Images.

ARCore API assumes that AR Images are static in the environment (2), so once they are recognized successfully, they will always appear in the list of anchors (updated list) (1) until the session is reset.

This means 2 things:

  1. AR Foundation will never mark the Tracked Image as removed, and it will never mark the Tracking State for the Tracked Image as None.
  2. If you try to test 2 Different Images via your monitor (desktop/laptop) and you will switch images with CMD+Tab (macOS) or Alt+Tab (Windows), so Images will be in the same position on the monitor, then ARCore will not understand that.

ARKit (iOS) Behavior

You can learn more about ARKit Requirements for Image Tracking here .

  1. Tracking State for the Tracked Image can be set as None when the camera stops seeing it.
  2. 2 images can be successfully tested on the monitor in the same position, as it described above for ARCore.

Read my Full Article about AR Testing here.


There are several updated resources to implement Multiple Image Tracking:

  • Official Unity Examples with Multiple Prefabs for different versions of AR Foundation: v5, v6.
  • My Example with Multiple Data (based on different Tracked Images) for the Only Game Object.

This is my base implementation of it:

private void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs args)
{
    foreach (ARTrackedImage arTrackedImage in args.added)
    {
        DebugPrinter.Print("added. Name: " + arTrackedImage.name);

        ShowContent(arTrackedImage, true);
    }

    // ----------------------------------------------------------------
    // ARCore NOTICE from https://makaka.org/unity-tutorials/ar-testing
    // ----------------------------------------------------------------
    // ARCore API assumes that AR Images are static in the environment
    // so once they are recognized successfully they will always appear
    // in the list of anchors until the session is reset. This means that
    // AR Foundation will never report that a tracked images is removed
    // nor will a tracked image's tracking state be reported as None.
    // args.updated contains all images that were added

    foreach (ARTrackedImage arTrackedImage in args.updated)
    {
        if (arTrackedImage.trackingState == TrackingState.Tracking)
        {
            ShowContent(arTrackedImage, true);
        }
        else
        {
            ShowContent(arTrackedImage, false);
        }

        //DebugPrinter.Print($"upd." +
        //    $" State: {arTrackedImage.trackingState}." +
        //    $" Name: {arTrackedImage.name}");
    }

    foreach (ARTrackedImage arTrackedImage in args.removed)
    {
        DebugPrinter.Print("removed. Name: " + arTrackedImage.name);

        ShowContent(arTrackedImage, false);
    }
}
1 Like

There is also such information in the mentioned Unity docs:

An image that goes out of view, for example, might not be “removed”, but its tracking state likely changes.

Actually, don’t worry about how removed is operated internally in ARKit/ARCore. You need to show the content when it’s relevant — my code provided above is enough for this task.

Thanks @makaka-org for your reply, i read and understood many resources around the web after some tests but the argument “removed” always confusing me.
Your reply is confirming me that at the moment this features is useless, and this is all i want to know for sure.
Otherwise if it was working, i would like to know where I was wrong implementing it.
Thanks again :slight_smile:

ARTrackablesChangedEventArgs<TTrackable>.Removed is called when the platform removes the trackable, not when it is removed from the library. This means that when Removed is called is platform specific. What @makaka-org said was right. ARCore and ARKit don’t remove images, just change their tracking state.

1 Like