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

    aneri1997

    Joined:
    Apr 5, 2020
    Posts:
    2
    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;
    8.  
    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
    15.  
    16.  
    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, Vector3.zero, Quaternion.identity);
    25. newARModel.name = aRModel.name;
    26. aRModels.Add(newARModel.name, newARModel);
    27. newARModel.SetActive(false);
    28. modelState.Add(newARModel.name, false);
    29. }
    30. }
    31.  
    32. private void OnEnable()
    33. {
    34. aRTrackedImageManager.trackedImagesChanged += ImageFound;
    35. }
    36.  
    37. private void OnDisable()
    38. {
    39. aRTrackedImageManager.trackedImagesChanged -= ImageFound;
    40. }
    41.  
    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. }
    62.  
    63. private void ShowARModel(ARTrackedImage trackedImage)
    64. {
    65. bool isModelActivated = modelState[trackedImage.referenceImage.name];
    66. if (!isModelActivated)
    67. {
    68.  
    69. GameObject aRModel = aRModels[trackedImage.referenceImage.name];
    70. aRModel.transform.position = trackedImage.transform.position;
    71. aRModel.transform.rotation = trackedImage.transform.rotation;
    72. aRModel.SetActive(true);
    73. modelState[trackedImage.referenceImage.name] = true;
    74. }
    75. else
    76. {
    77. GameObject aRModel = aRModels[trackedImage.referenceImage.name];
    78. aRModel.transform.position = trackedImage.transform.position;
    79. aRModel.transform.rotation = trackedImage.transform.rotation;
    80. }
    81. }
    82.  
    83. private void HideARModel(ARTrackedImage trackedImage)
    84. {
    85. bool isModelActivated = modelState[trackedImage.referenceImage.name];
    86. if (isModelActivated)
    87. {
    88. GameObject aRModel = aRModels[trackedImage.referenceImage.name];
    89. aRModel.SetActive(false);
    90. modelState[trackedImage.referenceImage.name] = false;
    91. }
    92. }
    93. }
    94.  




    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

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,151
  3. claudioocs7

    claudioocs7

    Joined:
    Sep 26, 2023
    Posts:
    7
    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

    mike-copley-unity

    Unity Technologies

    Joined:
    Dec 7, 2023
    Posts:
    17
    Hello,

    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

    LazuliteJaffer

    Joined:
    Feb 20, 2024
    Posts:
    2
    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

    simarlab

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

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,151
  8. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,151
    @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.