I’ve got my image tracking properly, but it never seems to get removed. My setup is simple, just one tracked image. Here is the function I use to handle the trackedImagesChanged event:
private void OnTrackedImagesChanged( ARTrackedImagesChangedEventArgs eventArgs )
{
if ( eventArgs.added.Count > 0 )
{
var tracked = eventArgs.added[0];
_startBeacon.SetActive( true );
_startBeacon.transform.position = tracked.transform.position;
_startBeacon.transform.rotation = tracked.transform.rotation;
Logger.Add( "Touch the green beacon!" );
}
if ( eventArgs.updated.Count > 0 )
{
var tracked = eventArgs.updated[0];
_startBeacon.transform.position = tracked.transform.position;
_startBeacon.transform.rotation = tracked.transform.rotation;
}
if ( eventArgs.removed.Count > 0 )
{
_startBeacon.SetActive( false );
Logger.Add( "Tracked image lost!" );
}
}
The “added” if statement runs once when it first detects the tracked image, but if I remove the image from view, the “removed” if statement is never triggered.
Am I misunderstanding how this event is meant to be used? Anyone else have this issue?
Ok… I was going to report a bug on the GitHub repo for ARFoundation samples, but I discovered that there are already two different threads (one & two) discussing the issue, which is present an ARFoundation 2 and 3, going back months ago and it remains unresolved.
It seems to me that the life cycle of an ARTrackedImage is fundamentally broken since it never appears in the “removed” list when the image is no longer tracked and it never reappears in the “added” list when tracking resumes.
Others in the threads I’ve linked report that the ARTrackedImage’s tracking state never reports TrackingState.None.
@tdmowrer can you weigh in on this? Will this bug be addressed?
I think it is appeared in removed list if only if you manually remove the image anchor from the AR tracking pipeline. Maybe you should set timer when camera is facing image’s last location and the tracking state is None. Remove image anchor manually when your elapsed time expired.