Stop tracking a already tracked image

Include the following details (edit as applicable):

  • Issue category: Image Tracking
  • Device type & OS version: Android
  • Host machine & OS version: Windows
  • Issue Environment : On Device
  • Xcode version: n/a
  • ARDK version: 1.0.1
  • Unity version: Unity 2020.3.1.3

Description of the issue:

I am trying to remove a image from being tracked with the ARImageDetectionManager once its already started being tracked.
The goal being once a image is detected, I spawn a prefab using the position and rotation, and than stop tracking it entirely so it doesnt show up in AnchorUpdated events. The prefab itself plays out a 10 second sequence, and once it finished I want to readd the image to be tracked again so if the user wants, at that point that can scan the image again to spawn the prefab again.

My problem is, I cannot get a tracked image to remove for the life of me. If I attempt to remove the image from being tracked before its started being tracked it removes just fine. But if I try to remove it from being tracked after it flags OnAnchorAdded, than nothing happens and AnchorUpdated continues to spam updates for the image I tried to remove.

One thing i’ve tried, which kind of works but inconsitently, is I remove the image from being tracked in a Coroutine with delays between each line of code, disabling and reenabling features. Example below:
imageManager.DisableFeatures();
yield return new WaitForSeconds(1);
imageManager.RemoveImage(reff);
yield return new WaitForSeconds(1);
imageManager.EnableFeatures();

Doing it this way however has a few issues:

  • I have to continue tracking for a few seconds before the image is actually removed from tracking
  • Reenabling features causes quite the stutter, presumably because its restarting the whole session maybe.
  • Half the time the image still isnt removed anyways and still flags Updates to the anchor.

I would just ignore the updates, and than when I’m ready to readd the image to tracking again, just stop ignoring them, but this causes my system to assume the image is in view even when its not.

Is there a way to clear all activated imageAnchors?

Any help would be greatly appreciated.

Hello Scott,

We are looking into this issue.

But in the meantime, we have a suggestion.
ARImageDetectionManager.RemoveImage and ARImageDetectionManager.AddImage should log a session config change that should refresh the session.

Is it possible for you to re-run the session after adding or removing the runtime detected image?

Hello Scott,

Here is some more information on things that you can try.

  • Try the IARSession.RemoveAnchor API with the anchor that was added on initially detecting the image. Note that this usage hasn’t been tested though.
  • We also suggest that you should keep tracking the image during the animation, as it will help to keep the prefab anchored to the image. Otherwise, it may drift/lose track as the user moves.
  • Re-running the session without, then with the image might work.
  • Another possible solution would be to use some game spawning logic.
    For example: On anchors added, spawn the prefab, play the animation, despawn the prefab. Then, only respawn the prefab if there is no existing prefab, and the image is in the camera view.

Hopefully, the above information helps, and please let us know how it works for you.

Hey thanks for the replies. For our current usecase we are spawning prefabs from the image target anchor location, and than anchor it to a plane afterwards as it plays out its event so losing tracking / drifting isnt a issue.
I have already tried calling RemoveAnchor on the image anchor, but that ended up just causing OnAnchorAdded for that anchor to be flagged immediately even if that image target wasnt in view, so unfortunately that wont work.
I had considered just checking if the image target is in view on AnchorUpdated after the initial spawn but didnt want to have to do FOV checks every frame, but this may be the best solution it sounds like.

Since this post I have tried manually setting up the entire session and image targets instead of using the provided managers, that way I can rerun / readd the image targets async which seemed to help with the stutter of the session rerunning, the stutter is still there but it seems to be much less and much less frequent. This method still flags AnchorUpdates for that image anchor, but does flag on AnchorAdded for the target again as well, which allows me to not do a FOV check.

So it would seem currently the best solutions are to do FOV checks on the image target after the initial prefab spawning, or to have a slight amount of stutter from the session rerunning allowing for AnchorAdded to be flagged for that anchor again when its in view.

Hello Scott,

Excellent. Glad you were able to find a solution. Please open a new topic if more help is needed. Thanks.