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?
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:
AR Foundation will never mark the Tracked Image as removed, and it will never mark the Tracking State for the Tracked Image as None.
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.
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 (paid) 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);
}
}
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
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.
When the camera is aimed at the target image, it’s state will constantly alternate between “Limit” and “Tracking”. And TrackingStage.None has never appeared .
After listening to this event using ARTrackablesChangedEvents.updated