"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

proper wya to destroy a Dataset on Unity

Hi everyone,

 

I've followed the following link for createing a dataset from an external path:

https://developer.vuforia.com/library/articles/Solution/Unity-Load-DataSet-from-SD-Card

 

I've successfully created and activate my dataset, now what I'm trying to do is to add a reset function which will reload the same dataset with a different setting (the use or not of extend tracking for example).

 

So far here what I've done:

 

public void DoAReset(){
		//deactive dataset
		ObjectTracker tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

		tracker.DeactivateDataSet (mDataset);


		List<string> trackableNames = new List<string> ();


		IEnumerable<TrackableBehaviour> trackableBehaviours = TrackerManager.Instance.GetStateManager ().GetTrackableBehaviours ();
		foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours) {
			if (mDataset.Contains (trackableBehaviour.Trackable)) {
				trackableNames.Add (trackableBehaviour.Trackable.Name);

			}
		}

		foreach (string trackableName in trackableNames) {
			GameObject go = GameObject.Find (trackableName);
			DefaultTrackableEventHandler tra = go.GetComponent<DefaultTrackableEventHandler> ();
			tra.StopTrackableEventHandler ();

		}


		//remove dataset
		tracker.DestroyDataSet (mDataset, false);

		//reset mLoaded and mDataset
		mDataset = null;
		mLoaded = false;//reload model
}

 

Here is the StopTrackableEventHandler function:

 

public void StopTrackableEventHandler(){
			if (mTrackableBehaviour) {
				mTrackableBehaviour.UnregisterTrackableEventHandler (this);
			}
			TrackerManager.Instance.GetStateManager ().DestroyTrackableBehavioursForTrackable (mTrackableBehaviour.Trackable, true);
			Destroy (mTrackableBehaviour);
}

 

 

With the following code, I have to problem:

1- for the line "tracker.DestroyDataSet (mDataset, false);", if I set the second parameter to "true", I'll have an error saying that the Trackable cannot be destroy

2- When I load my dataset, my 2 trackable receive as ID 1 and 2, but after calling the reset function, those ID changed to 4 and 5, then 7 and 8 if call reset again. It probably means that the previous ImageTarget were not completely destroyed but how can destroy any previous ImageTarget?

 

Could you please tell me the proper way to completely remove a dataset?

 

I really thank you in advance for your help

AlessandroB

Wed, 03/23/2016 - 08:53

Hi,

you can remove (destroy) Trackables from UserDefined Datasets (UDT), but you cannot remove them from a DataSet that was loaded from a .DAT / .XML file.

(The UDT Sample App also shows an example of removing trackables from a UDT Dataset, for example).

 

AlessandroB

Thu, 03/24/2016 - 15:50

I would probably suggest using a Dictionary, by which you can use the Trackable Names as Keys (kind of "IDs") and associate them with whatever object you want.

You could even combine the Dataset name + the Trackable name to be sure you get a unique name (hence a unique ID).