Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Delay required before adding image to ref library

Discussion in 'AR' started by douglassophies, Jun 8, 2021.

  1. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    I used this Unity example for adding images to a mutable image library: https://github.com/Unity-Technologi...Assets/Scenes/ImageTracking/DynamicLibrary.cs

    The sample has a button which if you click, will add an image to the library and the debug logs show the count go above 0.

    If i modify the buttons functionality is called directly from the Start() method, it does not work and shows an image count of 0.

    If I use a coroutine to wait before running the code, it works, suggesting there is something that needs to load before images can be added.

    Why is this? I cannot tell what is loading before hand that makes it fail before some time has passed.
     
  2. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    959
    I think you're trying to add an image when the underlying XRImageTrackingSubsystem is not yet created. Please try to wait until ARTrackedImageManager.subsystem != null.
     
  3. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    Thanks for the idea but it does not seem to be the issue. The subsystem is never null, even at the very beggining. (At least in my tests).
     
  4. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    959
    Could you please tell me what AR device do you have, iOS or Android?
    On Android, you should wait before ARSession.state is ARSessionState.SessionInitializing or SessionTracking to add an image to a mutable library successfully. I can't explain why this is happening, but this is how ARCore works.
     
    douglassophies likes this.
  5. douglassophies

    douglassophies

    Joined:
    Jun 17, 2012
    Posts:
    141
    I use
    Code (CSharp):
    1. while (ARSession.state != ARSessionState.SessionInitializing && ARSession.state != ARSessionState.SessionTracking)
    to force the app to wait before adding the images and this seems to have done the trick. Thanks!
    FYI, developing for both but was testing on Android.
     
    KirillKuzyk likes this.