Log in or register to post comments

Load dataset from external path

May 10, 2019 - 2:06am #1

Hi!

In my project I'm trying to edit my multi targets XML file to move targets around in runtime. However, since the streamingassets path is read only i need to store the xml in the persistentDataPath and load the data set from there, but I'm having no luck with that at the moment. This is the code I use now:

public void LoadAndActivateDataset(string loadThisDataset, ObjectTracker objectTracker)

    {

        TrackerManager trackerManager = (TrackerManager)TrackerManager.Instance;

        objectTracker.Stop();

        //Create a new dataset object.

        DataSet dataset = objectTracker.CreateDataSet();

       

        //Load and activate the dataset if it exists

        if (DataSet.Exists(loadThisDataset, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))

        {

            if (!dataset.Load(loadThisDataset, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))

            {

                Debug.LogError("Fail to load");

            }

            if (!objectTracker.ActivateDataSet(dataset))

            {

                // Note: ImageTracker cannot have more than 100 total targets activated

                Debug.LogError("Failed to activate dataset");

            }

        }

        objectTracker.Start();

    } 

loadThisDataset is the path to my xml file, i.e, Path.Combine(Application.persistentDataPath, "Warehouse.xml").

The message I get in the console from dataset.Load(loadThisDataset, VuforiaUnity.StorageType.STORAGE_ABSOLUTE) is:

Creating Multi Target with values:

ID:           1

Name:         WarehouseImages

Path:         C:/x/MSI/AppData/LocalLow/x/x/Warehouse.xml

And all that's happening is one game object being created with the Multi Target behaviour component but the Warehouse database is not found.

How am I doing this wrong, have I not understood how to work with datasets perhaps? I thought simply loading the xml would find my database and instantiate the multi target.

 

Any help would be greatly apprectiated!

 

Thanks

Load dataset from external path

May 15, 2019 - 3:27pm #6

Hello,

hassehans wrote:

I must be missing something, if this is the expected behaviour, why aren't the trackables being initiated? A working MultiTarget loaded normally looks like this in the hierarchy: MultiTarget>ChildTargets>trackable1.... etc. But my loaded dataset and database from my script in the first post only creates: New Game object, with Multi target behaviour but no children at all.

Is this really the expected behaviour or is this a bug/I'm missing the point completely?

Unfortunately, I cannot speak to what you're observing during Play Mode, or know what you should be seeing.

My troubleshooting approach would be to establish that the device database is working by using it in the Vuforia Core samples. We also have the Model Targets Test App for Android that can be used for the same testing: https://developer.vuforia.com/downloads/tool

Once you've established that the device database works, then the likely source of the error is with the dynamic loading and activating of your device database.

Thanks,

Vuforia Engine Support

Load dataset from external path

May 15, 2019 - 2:41am #5

Hi,

medabit wrote:

This is as expected. Please note that device databases only appear in the Unity Inspector when they been imported via Assets->Import Package->Custom package... This places the .unitypackage contents in Assets/StreamingAssets/Vuforia folder of your project, and that is the only place that Vuforia's Unity extension looks for these assets to show in the Editor's inspector window.

I must be missing something, if this is the expected behaviour, why aren't the trackables being initiated? A working MultiTarget loaded normally looks like this in the hierarchy: MultiTarget>ChildTargets>trackable1.... etc. But my loaded dataset and database from my script in the first post only creates: New Game object, with Multi target behaviour but no children at all.

Is this really the expected behaviour or is this a bug/I'm missing the point completely?

 

Thanks

Load dataset from external path

May 14, 2019 - 11:25am #4

Hello,

hassehans wrote:

Well, simply that both the Database and Multi Target dropdowns in the Multi Target Behaviour component says ---Empty---, and I can't see Warehouse under Database or WarehouseImages under Multitarget.

And no children under the new game object are created, so there are no trackables.

This is as expected. Please note that device databases only appear in the Unity Inspector when they been imported via Assets->Import Package->Custom package... This places the .unitypackage contents in Assets/StreamingAssets/Vuforia folder of your project, and that is the only place that Vuforia's Unity extension looks for these assets to show in the Editor's inspector window.

hassehans wrote:

Might I have placed some of the files wrong? As stated above I have the .dat .xml in my dataDersistentPath and the image jpgs in Asset/Editor/Vuforia/ImageTargetTextures/Warehouse.

To load and enable the device database, all you need is the DAT and XML file to be present in your path.

Here are some additional library articles that provide reference code for similar use cases:

The basic idea is that Vuforia device databases can be loaded from anywhere in device storage, as long as the app can read that location during run time.

Admittedly, our documentation is not completely comprehensive and will be improved over time.

Thanks,

Vuforia Engine Support

Load dataset from external path

May 14, 2019 - 12:51am #3

Hi medabit, sorry for the slow reply.

medabit wrote:

I'll assume that the DAT file is also in the same path. I believe this is confirmed by the logging message below.

Yes, the two sole files I have in C:/x/MSI/AppData/LocalLow/x/x/Warehouse.xml is Warehouse.xml and Warehouse.dat.

medabit wrote:

When you say "the Warehouse database is not found", how do you know this? Is it an error from the log messages? Or just that the target is not recognized by the SDK?

Well, simply that both the Database and Multi Target dropdowns in the Multi Target Behaviour component says ---Empty---, and I can't see Warehouse under Database or WarehouseImages under Multitarget.

And no children under the new game object are created, so there are no trackables.

Might I have placed some of the files wrong? As stated above I have the .dat .xml in my dataDersistentPath and the image jpgs in Asset/Editor/Vuforia/ImageTargetTextures/Warehouse.

Or do I have to create any game objects in advance? I have the script with my LoadAndActivateDataset method on an empty game object.

 

Thank you for your help!

Load dataset from external path

May 10, 2019 - 9:59am #2

Hello,

hassehans wrote:

loadThisDataset is the path to my xml file, i.e, Path.Combine(Application.persistentDataPath, "Warehouse.xml").

I'll assume that the DAT file is also in the same path. I believe this is confirmed by the logging message below.

hassehans wrote:

The message I get in the console from dataset.Load(loadThisDataset, VuforiaUnity.StorageType.STORAGE_ABSOLUTE) is:

Creating Multi Target with values:

ID:           1

Name:         WarehouseImages

Path:         C:/x/MSI/AppData/LocalLow/x/x/Warehouse.xml

This tells me that the device database was correctly loaded.

hassehans wrote:

And all that's happening is one game object being created with the Multi Target behaviour component but the Warehouse database is not found.

When you say "the Warehouse database is not found", how do you know this? Is it an error from the log messages? Or just that the target is not recognized by the SDK?

For the latter, I suggest you use our Core samples and swap out our Multi Target for yours to see if the behavior is the same.

hassehans wrote:

How am I doing this wrong, have I not understood how to work with datasets perhaps? I thought simply loading the xml would find my database and instantiate the multi target.

Here are some additional library articles that provide reference code for similar use cases:

Admittedly, our documentation is not comprehensive and will be improved over time.

Thanks,

Vuforia Engine Support

Log in or register to post comments