Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Clarification on ARTrackedImageManager and MutableRuntimeReferenceImageLibrary

Discussion in 'AR' started by acandael, May 4, 2022.

  1. acandael

    acandael

    Joined:
    Apr 7, 2021
    Posts:
    74
    Hello,

    I'm very new to ARFoundation, and I'm encountering problems using a MutableRuntimeReferenceImageLibrary.
    I have a ARTrackedImageManager that supports MutableImageLibraries (as reported by the ARTrackedImageManager.descriptor.supportsMutableLibrary boolean), but somehow when I try to add an image via
    mutableLibrary.ScheduleAddImageWithValidationJob
    , I get an error.

    Could you check my code below, and see if the reason of the error is due to something I do wrong? This is basically built from bits found on the documentation. And the bottom line is I end up with the console telling me "Job has completed with error ErrorUnknown".

    It's not shown here, but assume AddImage is called and fed via the following Texture2D:
    Code (CSharp):
    1.  
    2. byte[] qrCode=FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result[0]);
    3. Texture2D tex = new Texture2D(2,2);
    4. tex.LoadImage(qrCode);
    5.  
    Code (CSharp):
    1.  
    2. public class MarkerSelectionManager : MonoBehaviour
    3. {
    4.     private ARTrackedImageManager trackedImageManager;
    5.     public static MutableRuntimeReferenceImageLibrary mutableRuntimeImageLibrary;
    6.  
    7.     private void Start()
    8.     {
    9.         // Create a ARTrackedImageManager at runtime
    10.         trackedImageManager = gameObject.AddComponent<ARTrackedImageManager>();
    11.         trackedImageManager.trackedImagePrefab = null;
    12.    
    13.         // Create empty XRReferenceImageLibrary et runtime
    14.         RuntimeReferenceImageLibrary runtimeLibrary = trackedImageManager.CreateRuntimeLibrary();
    15.         trackedImageManager.enabled = true;
    16.         // Convert it to a MutableRuntimeReferenceImageLibrary
    17.         mutableRuntimeImageLibrary = runtimeLibrary as MutableRuntimeReferenceImageLibrary;
    18.  
    19.         if (DoesSupportMutableImageLibraries())
    20.         {
    21.             Debug.Log("trackedImageManager DOES support MutableImageLibraries");
    22.         }
    23.     }
    24.     bool DoesSupportMutableImageLibraries()
    25.     {
    26.         return trackedImageManager.descriptor.supportsMutableLibrary;
    27.     }
    28.     void AddImage(Texture2D imageToAdd)
    29.     {
    30.         Debug.Log("Now in AddImage");
    31.         if (mutableRuntimeImageLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
    32.         {
    33.             Debug.Log($"Adding image {imageToAdd.name} via schedule");
    34.             AddReferenceImageJobState job = mutableLibrary.ScheduleAddImageWithValidationJob(
    35.                 imageToAdd,
    36.                 "my new image",
    37.                 0.02f);
    38.             while (!job.jobHandle.IsCompleted)
    39.             {
    40.                 Debug.Log("Waiting for the job to complete");
    41.             }
    42.             if (job.status.IsError())
    43.             {
    44.                 Debug.Log($"Job has completed with error {job.status.ToString()}");
    45.             }
    46.         }
    47.         else
    48.         {
    49.             Debug.Log("mutableRuntimeImageLibrary is no Mutable");
    50.         }
    51.     }
    52.  
    I no clear mistake can be spotted here, maybe you have an idea where I could look?
    This is running on Unity 2020.3.18f1, AR Foundation package 4.1.7.


    Thanks a lot!
    Arnaud
     
    Last edited: May 4, 2022
  2. ankur-unity

    ankur-unity

    Unity Technologies

    Joined:
    Aug 12, 2021
    Posts:
    34
  3. acandael

    acandael

    Joined:
    Apr 7, 2021
    Posts:
    74