Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.04k stars 1.14k forks source link

How to Disable old prefabs of Image targets that are no longer being tracked? [ARCORE] [MULTI IMAGE TRACKING] #1028

Closed pinnakkkk closed 1 year ago

pinnakkkk commented 1 year ago

so I have a script that works fine for detection part, but sometimes the last tracked images doesn't change to SetActive(false), even though I'm making sure that they get disabled even when the trackingstate is set to limited. I tried the AR Foundations Demo too same issue old prefabs don't get disabled. it seems like that AR Core assumes both markers are still being tracked hence when checking for trackedImage.referenceImage.name I get both names hence my logic


if (allSpawnedPrefabs.name != current_tracked_image) {
 allSpawnedPrefabs.SetActive(false);
  } 
Unity3D-Hardik commented 1 year ago

https://github.com/Unity-Technologies/arfoundation-samples/blob/main/Assets/Scenes/ImageTracking/BasicImageTracking/TrackedImageInfoManager.cs

Check this script. In OnTrackedImagesChanged() method you will get the event-like status of the currently tracked image on the base of that you can create logic.

Let me know if you still have doubts I'll find the video and share it with you,

SimonDarksideJ commented 1 year ago

I have to point out @pinnakkkk that you cannot rely on the events coming out of ARCore / ARKit. Of note, you can see in line 82 of the above script:

https://github.com/Unity-Technologies/arfoundation-samples/blob/98b5aa9dbd639c741f8d22b5779df97c87feabe1/Assets/Scenes/ImageTracking/BasicImageTracking/TrackedImageInfoManager.cs#LL82

This checks if the item is NOT tracked or Tracked, although ARKit in particular will only mark an item as tracked in the first frame (detection) and marks it as "limited" in subsequent frames. But once it is tracked, it rarely goes back to not tracked. Android on the other hand will mark an item as tracked when detected and never uses "limited". Behaviour can also differ based on the device.

Just something you have to play with and work around

andyb-unity commented 1 year ago

Hi @pinnakkkk,

Are you still having issues? When checking the tracking status of an image, you should both check updated images for trackingState == TrackingState.Limited as well as check whether the tracked image was removed. Let us know if you have further questions.

pinnakkkk commented 1 year ago

Hi @pinnakkkk,

Are you still having issues? When checking the tracking status of an image, you should both check updated images for trackingState == TrackingState.Limited as well as check whether the tracked image was removed. Let us know if you have further questions.

Hello @andyb-unity ! Thankyou for replying, setting trackingState to limited works, however it doesn't really work if the you change the image like a slideshow the new image gets added & tracked but old image's prefab still exists unless u cause a massive disturbance between the camera & the image (like putting a hand in between), which removes both the image's prefab.

andyb-unity commented 1 year ago

In our experience yes that's correct. Neither ARCore nor ARKit handle image tracking well under digital slideshow conditions as you describe. (AR Foundation simply reports the tracking status of the underlying platform. It does not implement tracking itself.)

pinnakkkk commented 1 year ago

In our experience yes that's correct. Neither ARCore nor ARKit handle image tracking well under digital slideshow conditions as you describe. (AR Foundation simply reports the tracking status of the underlying platform. It does not implement tracking itself.)

That was pretty helpful!