Good morning everyone. I am writing to know if you can help me with a strange bug that I am facing working with Ar foundation, specifically with 2D Image traking.
My application is based on the tracking of a series of images (of the same size) which when framed generate a prefab with text and other contents, basic use of image traking.
To manage the despown of unframed images I used the classic trakedimage approach with the difference that I manage it directly from the prefab child of the trakedImage and not ARTrackedImageManager eventArgs.updated.
private void VisibilityCheck_Automatic()
{
if (m_trakedImage == null)
return;
if (!imageIsVisible)
{
if (m_trakedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Tracking)
{
imageIsVisible = true;
// active object
}
}
else
{
if (m_trakedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.Limited ||
m_trakedImage.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.None)
{
imageIsVisible = false;
// disable object
}
}
}
Now the bug is this.
When I am scrolling through the images recognized by the AP from the desktop (there are more than 100) it often happens that if two images alternate immediately (imagine that I have an image open, I press the right arrow to view the next image) the app fails to deactivate the first prefab that will remain present, under the newly spawned second prefab of the new card.
So the second image is recognized and the prefab is spawned, but the first prefab is not deactivated even if its image is no longer visible.
The strange thing is that this only happens if the second image is just immediately in the place where it was before. For example, if the second image takes a while to load, at that time the app no longer sees the first image deactivates it correctly and the bug does not happen. If the two images are not in the same place or one image is moved, there is no problem.
To fix the bug I just stop framing the image for a second and when I get back the first prefab is correctly gone, but it’s very annoying. I have also tried to manage the deactivation with other methods like a raycast, but the problem persists on android and IOS.
Ar foundation 4.19, Unity 2020.3.28.f1