Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Multiple XRReferenceImageLibraries created from script in Editor

Discussion in 'AR' started by FOKSlab, Dec 6, 2023.

  1. FOKSlab


    Jun 27, 2017

    I am trying to generate an app on iOS using 3 XRReferenceImageLibraries. No issue when building for Android but ithere is a bug when building for iOS:
    - When doing only 1 XRReferenceImageLibrary for all the images (137 !), one of the image generates an issue (Warning: unable to add AR reference image rendition ... ignoring) and all the next images are not added too (Warning: unable to add AR reference image facet ... [errno = 28] ignoring).
    - When separating the XRRefenceImageLibrary into 3 XRReferenceImageLibraries the issues are the same (I though it could be the maximum number of images in each XRReferenceImageLibrary which could be limited on iOS) : same images are generating the same warnings / errors. there are more of less 50 images in each XRReferenceImageLibrary.
    - But when using only 1 of the 3 (the one containing the first image generating the issue) the build succeeds :) and tracking seems to be OK even for the images rejected before.

    So it seems it was not the image which is the issue but the way ARKit is managing the trackable images.
    Can I use multiple XRReferenceImageLibrary in the same project with iOS ?
    Has someone got an idea to deal with that ? Is it a bug ?

    NB : Only 1 XRReferenceImageLibrary is used per scene and only 1 scene is loaded at a time (ARSession is reseted each time). I am using Unity 2022.3.14f1 with ARFoundation 5.1.1

    Hope you can help.

    PS : the XRReferenceImageLibraries are created from an Editor Script (using , and I have to lock one inspector per XRReferenceImageLibrary so Unity does not clear the database when opening another scene.

    Process to create each XRReferenceImageLibrary :
    Code (CSharp):
    1. string name = AssetDatabase.GenerateUniqueAssetPath("Assets/Resources/AR_BDD/AR_lib.asset");
    2. XRReferenceImageLibrary lib = ScriptableObject.CreateInstance<XRReferenceImageLibrary>();
    3. AssetDatabase.CreateAsset(lib, name);
    Process to add an image in a database (giving the index):

    Code (CSharp):
    1. XRReferenceImageLibraryExtensions.Add(lib);
    2. XRReferenceImageLibraryExtensions.SetName(lib,  index , image_name);
    3. XRReferenceImageLibraryExtensions.SetSpecifySize(lib index, true);
    4. XRReferenceImageLibraryExtensions.SetSize(lib, index, new Vector2(image_width, image_height));
    5. XRReferenceImageLibraryExtensions.SetTexture(lib, index, image_texture, false);
    And eventually :

    Code (CSharp):
    1. AssetDatabase.SaveAssets();
    2. AssetDataBase.Refresh();
    NB : Database are created but seems not to be managed properly by Unity (2022.3.14f1) since I have to lock their inspectors to keep them OK before build (and first image of the XRReferenceImageLibraries are blinking in Inspector).
  2. thomas_key


    Unity Technologies

    Dec 14, 2019
    If you're scripting your own build pipeline and the image libraries are created as part of that, you may want to look at calling ARBuildProcessor.PreprocessBuild(...). Otherwise I'm not aware of any hard limits for XRImageReferenceLibrary and you should create a bug report so we can track and report when it's fixed.