Search Unity

Question ARAnchors not working after load Mutable Image Library

Discussion in 'AR' started by esr184, Dec 3, 2021.

  1. esr184

    esr184

    Joined:
    Apr 21, 2014
    Posts:
    2
    Hi,

    We’re currently working on an AR App using ARFoundation and ARCore.

    In the app we use a MutableRuntimeReferenceImageLibrary assigned to a TrackingImageManager to load image markers from a Texture2D (we load the texture2D from a byte array, not from a texture asset).

    This part is working properly, the image marker gets detected and the TrackingImageManager raises all the expected events. However, it seems that when we load the images to the mutable library at runtime the ARAnchors stop working for some reason. Instead of staying on their anchored position they move with the camera. We tried using point anchors and plane anchors, neither worked.

    This doesn’t happen when we use image markers set to the Marker Library asset from the inspector, only when the marker has been loaded at runtime.

    What we want to achieve is to locate the image tracker once and set up an anchor as an origin position, so even if the image tracker is not visible all the AR elements stay at a stable position. (The image tracker Will always be in the same position, so there is no need to keep track of the image marker position every frame).

    Here is the function that we are using to load the textures into the library:

    Code (CSharp):
    1.  
    2. public async Task<bool> LoadMarker(Texture2D texture, string name)
    3. {        
    4.     if (!texture.isReadable)
    5.     {
    6.         return false;
    7.     }
    8.  
    9.     if (!(_arTrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary))
    10.     {
    11.         return false;
    12.     }
    13.  
    14.     AddReferenceImageJobState jobState = mutableLibrary.ScheduleAddImageWithValidationJob(texture, name, 0.25f);
    15.  
    16.      while (!jobState.jobHandle.IsCompleted)
    17.          await Task.Delay(1);
    18.  
    19.     if (jobState.status != AddReferenceImageJobStatus.Success)
    20.     {
    21.        return false;
    22.     }
    23.  
    24.     return true;
    25. }
    The tracking stability is quite bad, especially when the image marker is not on screen all the elements and we think that the fact that the ARAnchors are not setting properly is what’s causing this issue.

    If anyone knows what could be causing this issue we would gladly appreciate it. Since we are starting to lose our sanity…

    Thanks in advance.
     
  2. todds_unity

    todds_unity

    Joined:
    Aug 1, 2018
    Posts:
    324