Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug AR Image Tracking not working in iOS but working fine in Android

Discussion in 'AR' started by aneri1997, Feb 10, 2024.

  1. aneri1997


    Apr 5, 2020
    Hi, I have developed an AR app which tracks multiple images and renders AR models onto it. It contains 20 image targets with 20 models, So first I built it for Android and published on the play store, everything worked fine. But as soon as I built it for iOS, firstly for 20 images, camera din't open and the app crashed, so I thought it must be memory issue, therefore for the trail purpose I only kept 3 images and their corresponding models should come up.

    When run on iPhone or iPad, it constantly shows "Tracking Lost" text and doesn't render the model.
    When run on Android for how much ever images, works completely fine.

    For AR image tracking I am using this script :-

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.ARFoundation;
    6. using UnityEngine.XR.ARSubsystems;
    7. using TMPro;
    9. public class MultiTargetManager : MonoBehaviour
    10. {
    11. [SerializeField] private ARTrackedImageManager aRTrackedImageManager;
    12. [SerializeField] private GameObject[] aRModelsToPlace;
    13. //[SerializeField] private GameObject ArMain;
    14. [SerializeField] private GameObject trackingLostPopup; // Popup to show when tracking is lost
    17. private Dictionary<string, GameObject> aRModels = new Dictionary<string, GameObject>();
    18. private Dictionary<string, bool> modelState = new Dictionary<string, bool>();
    19. // Start is called before the first frame update
    20. void Start()
    21. {
    22. foreach (var aRModel in aRModelsToPlace)
    23. {
    24. GameObject newARModel = Instantiate(aRModel,, Quaternion.identity);
    25. =;
    26. aRModels.Add(, newARModel);
    27. newARModel.SetActive(false);
    28. modelState.Add(, false);
    29. }
    30. }
    32. private void OnEnable()
    33. {
    34. aRTrackedImageManager.trackedImagesChanged += ImageFound;
    35. }
    37. private void OnDisable()
    38. {
    39. aRTrackedImageManager.trackedImagesChanged -= ImageFound;
    40. }
    42. private void ImageFound(ARTrackedImagesChangedEventArgs eventData)
    43. {
    44. foreach (var trackedImage in eventData.added)
    45. {
    46. ShowARModel(trackedImage);
    47. }
    48. foreach (var trackedImage in eventData.updated)
    49. {
    50. if (trackedImage.trackingState == TrackingState.Tracking)
    51. {
    52. ShowARModel(trackedImage);
    53. trackingLostPopup.GetComponent<TextMeshProUGUI>().text = "Tracking Active";
    54. }
    55. else if(trackedImage.trackingState == TrackingState.Limited)
    56. {
    57. HideARModel(trackedImage);
    58. trackingLostPopup.GetComponent<TextMeshProUGUI>().text = "Tracking Lost";
    59. }
    60. }
    61. }
    63. private void ShowARModel(ARTrackedImage trackedImage)
    64. {
    65. bool isModelActivated = modelState[];
    66. if (!isModelActivated)
    67. {
    69. GameObject aRModel = aRModels[];
    70. aRModel.transform.position = trackedImage.transform.position;
    71. aRModel.transform.rotation = trackedImage.transform.rotation;
    72. aRModel.SetActive(true);
    73. modelState[] = true;
    74. }
    75. else
    76. {
    77. GameObject aRModel = aRModels[];
    78. aRModel.transform.position = trackedImage.transform.position;
    79. aRModel.transform.rotation = trackedImage.transform.rotation;
    80. }
    81. }
    83. private void HideARModel(ARTrackedImage trackedImage)
    84. {
    85. bool isModelActivated = modelState[];
    86. if (isModelActivated)
    87. {
    88. GameObject aRModel = aRModels[];
    89. aRModel.SetActive(false);
    90. modelState[] = false;
    91. }
    92. }
    93. }

    Versions i am using :-
    Unity - 2021.3.28f1
    AR Foundation - 4.2.10
    AR Kit - 4.2.10
    AR Core - 4.2.10
    XR Plugin Management - 4.3.3

    I tried the project in Unity 2021.3.15f1
    AR Kit - 4.2.9

    Still doesn't work.

    Here is the image of my Player Settings.

    Please help me resolve this issue.

    Also, I wanted to downgrade the AR Kit versions, but dint find a way to do so.

    Thanks in Advance
  2. andyb-unity


    Unity Technologies

    Feb 10, 2022
  3. claudioocs7


    Sep 26, 2023
    I'm not quite having the same issue but something you mentioned happened to me as well. I developed an app that tracks 2D images and displays a video on top of them using a Quad with a video player in a prefab to display it.

    The issue is that I build it for Android and everything came out well same as you did, but when I build for IOS and scan the image that is in the reference library the prefab appears (and I can notice because I have a UI element on it) but the actual Quad with the video player that is supposed to be on top of the image is nowhere to be found.
    Through several testing I noticed that the Quad does appear but it is very off when it comes to the place where it supposed to be which is on top of the image. I tried to change position, play with the scale, size but nothing the Quad still appears very far away, too close to see it or tillted in a strange way. I'm not able to find the sweet spot like on Android that it just appears on top of the scanned image.
  4. mike-copley-unity


    Unity Technologies

    Dec 7, 2023

    If either @aneri1997 or @claudioocs7 could confirm whether or not they get this behavior within the sample app -- the link provided by @andyb-unity above, they will help us narrow down whether the issue lies within the AR Foundation package, or relates to some detail that is specific to your code.
  5. LazuliteJaffer


    Feb 20, 2024
    I am having this issue on the sample project you provided, it works fine on android but not on IOS. On IOS it didn't track anything but ask for camera permission. I am not sure if it tracks the image but the 3d model I want to instantiate on top of it didn't appear
  6. simarlab


    Jul 21, 2021
    I can confirm that on IOS is not working good the TrackingState, it's always limited.
  7. andyb-unity


    Unity Technologies

    Feb 10, 2022
  8. andyb-unity


    Unity Technologies

    Feb 10, 2022
    @simarlab I just reproduced your report of "tracking state always Limited" on my iPhone 13 Pro. After an initial review of our plug-in code, this looks to be an Apple issue. Our plug-in simply reports the data that we receive from Apple.

    Out of curiosity, did you test with a digital image on a screen, or a printout of the image? My test was digital, and I suspect that iOS would perform better with a higher pixel-density printout.