Search Unity

Bug Loading XRReferenceImageLibrary through Addressables runs in Editor but Android Builds crash

Discussion in 'AR' started by BanzBowinkel, Aug 26, 2022.

  1. BanzBowinkel

    BanzBowinkel

    Joined:
    Jun 17, 2015
    Posts:
    16
    Hi all:

    I use AR Foundation with ImageTracking and keep the XRReferenceimagelibrary up to date through addressables so I don't have to release a new build every time I expand the library by a new image.

    Therefor I built a reference-image-library, marked it as addressable, load it at start and set it in the (disabled) TrackedImageManager at runtime. Then I activate the TrackedImageManager.
    So far so good! Works fine in Unity 2020.3.36, Addressables 1.18. and AR Foundation 4.1.16.
    as well as in Editor and in the Android-Build (IL2CPP)

    Here's the catch:
    After updating to 2021.3.8 with Addressables 1.19 and AR Foundation 4.2.3 still everything works fine in the editor but my builds for Android keep crashing. In Logcat I get this:

    InvalidOperationException: Failed to load XRReferenceImageLibrary, library does not contain any ARCore data.

    Does anybody know how to deal with this? I rebuilt the whole setup in a new project: same problem.
    The AR Foundation 4.2.3 documentation says referencelibraries can now be updated through addressables:

    https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/manual/tracked-image-manager.html


    Ironically in AR Foundation 4.1. it is working though from the 4.2. doc it should not, whereas in the version that brags with this feature I get build-crashes. Or am I missing something? When I set a serialized referenceLibrary at runtime everything works. So from my understanding it has got to do with the referencelibrary downloaded as addressable not beeing read properly.

    Here's the code I use to set up the library:
    Code (CSharp):
    1.  
    2. public void LoadReferenceLibrary()
    3. {
    4.     referenceLibraryHandle = Addressables.LoadAssetAsync<XRReferenceImageLibrary>(key);
    5.     referenceLibraryHandle.Completed += ReferenceLibraryHandle_Completed;
    6. }
    7.  
    8. void ReferenceLibraryHandle_Completed(AsyncOperationHandle<XRReferenceImageLibrary> handle)
    9. {
    10.     if (handle.Status == AsyncOperationStatus.Succeeded)
    11.     {
    12.         xRReferenceImageLibrary = handle.Result;
    13.         TrackedImageManager.referenceLibrary = xRReferenceImageLibrary;
    14.         TrackedImageManager.enabled = true;
    15.     }
    16. }
    17.  
    Really nothing fancy at all and from my understanding according to what they say in the docs...
    If you have any ideas how to get past this I'd really appreciate that - for three days now I am trying to wrap my head around this... thx


     

    Attached Files:

  2. lookoutking

    lookoutking

    Joined:
    Nov 28, 2015
    Posts:
    5
    Did you get a solution?
    I have the same issue on Unity 2021.3.6f1, Addressable 1.19, and ARFoundation 5.0.2.
     
    BanzBowinkel likes this.
  3. BanzBowinkel

    BanzBowinkel

    Joined:
    Jun 17, 2015
    Posts:
    16
    No, I didn't. Unfortunately! I went on with the original setup I had.
    I saw there have been updates for ARFoundation as well as the Unity 2021 and Addressables version.
    I might give it a second try sometime hoping the updates will fixe the issue.
    But more I hope that someone could give me some insights on this issue! The poor echo on this thread makes me think I lack some understanding here.
    I would greatly appreciate some clarification why this is happening...
     
    lookoutking likes this.
  4. lookoutking

    lookoutking

    Joined:
    Nov 28, 2015
    Posts:
    5
    I agree. It is weird that it works on ARFoundation 4.1 but not 4.2 or even newer 5.0.2.
    BTW, do you successfully update the content of XRRerefenceImageLibrary with the original setup?
    I tried to update the reference images in the library with Addressables update workflow but it didn't work.
     
  5. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Just chiming in on this conversation to request that one or both of you file a bug: https://unity3d.com/unity/qa/bug-reporting

    I personally have never tried to use Addressables with AR Foundation so I don't have much to contribute to this conversation, but if you file a bug our QA team will be able to triage and ultimately assign this work to the right team.
     
    BanzBowinkel and lookoutking like this.
  6. BanzBowinkel

    BanzBowinkel

    Joined:
    Jun 17, 2015
    Posts:
    16
    Yes, I managed to do that. Changing the XRReeferenceImageLibrary and having the app reflect those changes seemed to work. I use CloudContentDelivery from UnityServices to host the Bundles btw. Though I got to admit that I didn't test it thoroughly yet.
     
  7. azukiidx

    azukiidx

    Joined:
    Nov 22, 2017
    Posts:
    9
    I've same issue..
    is there any solution ?
     
  8. Sarahim

    Sarahim

    Joined:
    Jan 10, 2021
    Posts:
    1
    Same problem here...any updates?
     
  9. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  10. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
  11. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Note our FAQ:

     
  12. Luchianno

    Luchianno

    Joined:
    Nov 22, 2013
    Posts:
    9
    Same problem here!
     
  13. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    As you requested, I submitted a bug for this (IN-55364) but was waiting for it to be added to the public bug tracker before posting about it here.
     
  14. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Thank you @luvcraft! I see our QA team is awaiting a response from you about a repro project. Please respond when you get the chance, or if you'd like to reach out directly to your Unity account rep about the issue we can hopefully help this issue land with a public issuetracker link.

    I've also notified some relevant folks as another similar report came in.
     
    luvcraft likes this.
  15. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    repro project was shared with Liutaurus on the 29th, but status is still "In Review". Let me know if I should share it some other way as well.
     
  16. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  17. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    Thanks, Andy! This looks very similar, but in my case it won't run in editor, either. It gives the error:
    “InvalidOperationException: Failed to load XRReferenceImageLibrary ‘LIBRARY NAME’: library does not contain any ARCore data.“ is present


    I have a repro project for it, which I've sent to Liutauras. Should I send it somewhere else instead?
     
  18. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    You've done everything right here-- we can access the repro projects from incoming bug tickets if we know the bug number. I've updated that GitHub issue with your report as well.
     
  19. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    awesome! thanks!
     
  20. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Hey @luvcraft, we have an update on the AssetBundles case. This is currently almost completely undocumented, but you must call ARBuildProcessor.PreprocessBuild in your AssetBundle build script, before you actually build the AssetBundles. We are working on changes to all versions of AR Foundation to make this easier and better documented, as we had no idea about this either. Thanks for helping this issue get some attention.
     
    luvcraft likes this.
  21. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
  22. luvcraft

    luvcraft

    Joined:
    Aug 22, 2011
    Posts:
    76
    Hooray! That fixed it! For anyone else who needs help with this, here's how I implemented it:

    I created a new addressables build script in an
    Editor
    folder:

    Code (CSharp):
    1. using UnityEditor.AddressableAssets.Build;
    2. using UnityEditor.AddressableAssets.Build.DataBuilders;
    3. using UnityEditor.XR.ARSubsystems;
    4. using UnityEngine;
    5.  
    6. [CreateAssetMenu(fileName = "BuildScriptTrackedImage.asset", menuName = "Addressables/Content Builders/Tracked Image Build Script")]
    7. public class TrackedImageBuildScript : BuildScriptPackedMode
    8. {
    9.     /// <inheritdoc />
    10.     public override string Name => "Tracked Image Build Script";
    11.  
    12.     protected override TResult BuildDataImplementation<TResult>(AddressablesDataBuilderInput builderInput)
    13.     {
    14.         Debug.Log("Running ARBuildProcessor.PreprocessBuild()");
    15.         ARBuildProcessor.PreprocessBuild(builderInput.Target);
    16.  
    17.         return base.BuildDataImplementation<TResult>(builderInput);
    18.     }
    19. }
    Then I created an object with that script attached, and added that object to the "Build and Play Mode Scripts" list in
    AddressableAssetSettings
    .
    upload_2023-10-21_12-25-22.png

    That made my script show up under "Default Build Script" in the "Addressables Groups" window:
    upload_2023-10-21_12-25-6.png

    Then I ran that to create a new addressables bundle, and then built the project, and it worked! Hooray!
     
    andyb-unity and BanzBowinkel like this.
  23. devy1451

    devy1451

    Joined:
    Oct 6, 2018
    Posts:
    2
    okay but that show a error when I built it:
    he type or namespace name 'AddressableAssets' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
     
  24. devy1451

    devy1451

    Joined:
    Oct 6, 2018
    Posts:
    2
    oookay, I solved the error, my bad xD, but what is the order ? First Build "Default Build Script" and then "Tracked Image Build" ? And for updates, only "Update a Previus Build" or with "Tracked Image Build" too ?
     
  25. chiangandyandy

    chiangandyandy

    Joined:
    May 16, 2013
    Posts:
    2
    since I have project working on arcore now, I need to solve this issue too. According to expert's description to solve issue by adding script on addressable editor. Unfortunately I don't know how to modify addressable editor. :(
    Does everyone can describe more detail how to make it to solve issue?
    Any help will be appreciated. :)

    Andy
     
    Last edited: Dec 22, 2023
  26. chiangandyandy

    chiangandyandy

    Joined:
    May 16, 2013
    Posts:
    2
    After use my brain to figure out, finally I solve this issue. so happy! according to your question, I think you only do the "Tracked Image Build" operation, doesn't need to do "Default Build Script" because "Tracked Image Build" is inherited from "Default Build Script".

    Andy