Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.03k stars 1.12k forks source link

Adding image to MutableRuntimeReferenceLibrary returns the status "ErrorUnknown" #932

Closed p-agostinho closed 2 years ago

p-agostinho commented 2 years ago

Hi! I'm trying to add images to the tracked image manager in runtime, using the following code:

`void AddImage(Texture2D imageToAdd) {

    if (m_TrackedImageManager.referenceLibrary is MutableRuntimeReferenceImageLibrary mutableLibrary)
    {

        //Used in case the image is in a TextureFormat not supported by the image library
        if (imageToAdd.format != TextureFormat.RGBA32)
        {
            Debug.Log("Different format");
            imageToAdd = ChangeFormat(imageToAdd, TextureFormat.RGBA32);
        }

        //Add the image to the library
        var addImageJob = mutableLibrary.ScheduleAddImageWithValidationJob(
            imageToAdd,
            "john",
            0.3f);

        //Wait for the add image job to end while debugging its status
        while (!addImageJob.jobHandle.IsCompleted)
        {
            Debug.Log("Adding images");
            Debug.Log("Status: " + addImageJob.status);
        }

        Debug.Log("Status: " + addImageJob.status);

        Debug.Log("Library Count: " + mutableLibrary.count);

    }
}`

In the process of adding the image, the status is logged as "None" several times, but eventually it becomes "Error Unknown".

I have tested this with different images and they all return the same result - both jpg's and png's.

I also thought that it could happen because the image had insufficient features. However, I also tried with the example marker in ARCore page and even used their arcoreimg tool to check the quality score of the images I used.

Do you know what can be the cause of this error? I know it says it is unknown, but it probably has a solution :).

Thanks!

tdmowrer commented 2 years ago

I would have a look at the output from logcat (adb logcat from the command line). ARCore often emits useful information that may help track it down.

p-agostinho commented 2 years ago

I would have a look at the output from logcat (adb logcat from the command line). ARCore often emits useful information that may help track it down.

Turns out I can't add the images neither on onAwake(), onStart() and onEnable() because the ARSession is still checking the availability.

void Start() { ARSession.stateChanged += ARSessionStateChanged; }

void ARSessionStateChanged(ARSessionStateChangedEventArgs obj) { if (obj.state == ARSessionState.SessionInitializing) { AddImage(); } }

It only works if I add the images when the AR Session state becomes "SessionInitializing".

Is this normal, or should I be able to add the images on the Start and Awake functions?

Thanks!

todds-unity commented 2 years ago

You need a session to create a runtime augmented database.