Search Unity

Bug AR Anchors lose tracking when more of them are added

Discussion in 'AR' started by unity_6lFscwL5Mm2QPQ, May 26, 2021.

  1. unity_6lFscwL5Mm2QPQ

    unity_6lFscwL5Mm2QPQ

    Joined:
    May 14, 2021
    Posts:
    3
    I am creating an anchor every second in Update() like this:

    Code (CSharp):
    1.  
    2. if (m_RaycastManager.Raycast(new Vector2((Screen.width / 2), (Screen.height / 2)), s_Hits, TrackableType.FeaturePoint))
    3.         {
    4.             var hitPose = s_Hits[0].pose;
    5.             var anchor = m_AnchorManager.AddAnchor(hitPose);
    6.             if (anchor == null)
    7.             {
    8.                 Debug.LogError("Error creating reference point");
    9.             }
    10.             else
    11.             {
    12.                 m_AnchorManager.Add(anchor);
    13.             }      
    14. }
    15.  
    I also have an anchor prefab set in ARAnchorManager, so that I can see when the AR Anchor is placed.
    When I start creating anchors, app works as desired - if I lose tracking (e.g. covering phone camera with a finger), and then point my camera at the real world area, where AR Anchors were previously created, it updates and resets all AR Anchors to original position and rotation.
    However, as I continue to move in real world space, creating more AR Anchors, at some point if I lose session tracking and try to recover it by looking with my phone camera at the recently anchored area (anchored with later created AR anchors), it will not recover the tracking of AR Anchors, even if I am pointing my phone camera (almost) exactly at the some spot and same angle, as it was when AR Anchors were created.
    The interesting fact is, that if I move to area where the first few AR anchors were created, the tracking will reset to proper position and rotation. But as I said, rescanning inside the "newer" area never repositions the anchors.

    Is there a limit on how many AR Anchors can be tracked at the same time? Or is this a bug? I also tried removing older AR Anchors when adding new ones, but it didn't help.

    I am using AR Foundation 4.0.2
     
  2. mdYeet

    mdYeet

    Joined:
    Oct 21, 2020
    Posts:
    22
    What purpose are you using anchors for? I usually use plane tracking and then parent a GameObject as a child onto an AR anchor. This is just to make sure it doesn't drift.
     
  3. unity_6lFscwL5Mm2QPQ

    unity_6lFscwL5Mm2QPQ

    Joined:
    May 14, 2021
    Posts:
    3
    I am placing large GameObject in AR, and I am trying to make world tracking as accurate as possible, so that when I move camera a few metres away and look around (losing direct contact of camera view with the first AR Anchor), the GameObject stays in same position as it was when it was being placed it in AR.
    I am parenting this GameObject to the first created AR Anchor, and I am creating multiple AR anchors without a child object to achieve that every time I create a new anchor, the GameObject is in correct position (because it still can see the latest created AR Anchor). And also if I lose tracking for a moment, it can easily recalibrate to previous position, because there are AR Anchors all around the camera to help with recalibration.
    Maybe this is not the best approach to make tracking of large GameObjects as accurate as possible, but I can't think of any other way since there is no official documentation on how to tackle this issue.
     
  4. FrankvHoof

    FrankvHoof

    Joined:
    Nov 3, 2014
    Posts:
    258
    The amount of AR Anchors that can be tracked at any time is dependent on the underlying XR Plugin (ARKit/ARCore) and the hardware you are running on. Once the 'limit' has been reached (they become too performance-intensive), older Anchors will track less often/accurate.

    From Unity's documentation
    Code (CSharp):
    1. The device typically performs additional work to update the position and orientation of the anchor throughout its lifetime. Because anchors are generally resource-intensive objects, you should use them sparingly.
    I'm not sure whether the XR Plugins (ARCore/ARKit) actually delete/release their internal representations of AR Anchors when they are deleted in Unity (if they're not, this might be a bug).