Topic has a solution
Log in or register to post comments

CreateImageTarget(string databasePath, string targetName) working in editor Play mode but not in build Android

Unity Editor
April 13, 2022 - 6:12am #1
Topic solved

Hello,

 

I am working on Unity 2020.3.31f1 LTS version and using Vuforia 10.6.3.

I am simply trying to create an Image Target Behaviour from a target stored in a Vuforia database not in the assets of the project with the method public ImageTargetBehaviour CreateImageTarget(string databasePath, string targetName). The script I created is as follows:

using System.Collections.Generic;

using System.IO;

using UnityEngine;

using Vuforia;

public class CreateFromDatabase : MonoBehaviour

{

    //private string dataSetPath = "/storage/emulated/0/UnityTests/joconde/joconde.xml";

    private string dataSetPath = "d:/UnityTestsAssets/joconde/joconde.xml";

    private string targetName = "videotrackingcheck";

    // Start is called before the first frame update

    void Start()

    {

        VuforiaApplication.Instance.OnVuforiaStarted += LoadFromDatabase;

    }



    // Load and activate a data set at the given path.

    private void LoadFromDatabase()

    {

        // Check if the database set exists at the given path.

        if (!File.Exists(dataSetPath))

        {

            Debug.LogError("Data set " + dataSetPath + " does not exist.");

        }

        else

        {

            // Create an Image Target from the database.

           

            var mImageTarget = VuforiaBehaviour.Instance.ObserverFactory.CreateImageTarget(dataSetPath,targetName);

            mImageTarget.gameObject.AddComponent<DefaultObserverEventHandler>();

        }

    }

}

This script is attached to the ARCamera of my scene. It works perfectly fine in Play mode in the Unity Editor: the image target is created and my image is detected/tracked by testing with my PC webcam. The xml file of the database is located at "d:/UnityTestsAssets/joconde/joconde.xml" with the .dat file associated in the same directory, which is the absolute path I am sending to create the target.

However when I try to do the exact same thing by building the scene and run it on my Android phone by sending the absolute path of the xml file in my phone directories ("/storage/emulated/0/UnityTests/joconde/joconde.xml"), there is an error "Exception in callback: Failed to create ImageTargetObserver: DATABASE_LOAD_ERROR." in the log. Therefore the image target is not created.

You will find attached a screenshot of the error seen in the Android Logcat, and a zip directory with the .dat and .xml files.

I have been trying to understand the problem for several days now and I am stuck. I already looked up on the internet to find clues but the discussions are in general not recent.

 

Thank you in advance.

AttachmentSize
Image icon DATABASE_LOAD_ERROR_Unity.png132.4 KB
Package icon joconde.zip51.24 KB
Platform: 

CreateImageTarget(string databasePath, string targetName) working in editor Play mode but not in build Android

April 29, 2022 - 1:34am #3

Hello,

I think you must be right. A solution I found to get around this problem is to put the files in Application.persistentDataPath because the app seems to have access to them here and there aren't any DATABSE_LOAD_ERROR anymore. You can either download the files by URL or find a way to copy paste them from somewhere in the internal memory of the app to the Application.persistentDataPath. I hope this will help if someone ever gets this problem.

 

Thank you!

CreateImageTarget(string databasePath, string targetName) working in editor Play mode but not in build Android

April 15, 2022 - 10:07am #2

Hello,

First thought from your description is that the app is not able to access that directory. Android applications typically are only allowed to access their private file system. The level of these restrictions are dependent upon the version of Android your building.

Kind regards,

Dave Downing

Vuforia Engine Technical Support

Log in or register to post comments