Log in or register to post comments

proper wya to destroy a Dataset on Unity

March 15, 2016 - 2:48am #1

Hi everyone,


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



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

proper wya to destroy a Dataset on Unity

March 24, 2016 - 5:06pm #5



Thank you for your reply.

Thank you for your suggestion. I'll try to do some test later using your suggestion.


Thank you for your help and your time

proper wya to destroy a Dataset on Unity

March 24, 2016 - 8:50am #4

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).


proper wya to destroy a Dataset on Unity

March 23, 2016 - 2:10am #3



Thank you for your reply and your explanation.


In my project, I'm using the generated ID as a reference for showing for each marker a plane with a specific material (marker1 will show "1" in the plane object, marker2 will show "2" in the plane object and so on), is there anyway to reset this internal ID counter?

I can parse the xml tracking file (the one with the dat file downloaded from the portal) and check the trackable name for checking the marker number but it'll be much easier if I could "simply" reset the ID counter :)


So far, in order to always have the right generated ID, I'm still using the code in my first post but I reload the entire scene next(which is, in my opinion, a really  dirty way of doing it)

I really thank you for your help

proper wya to destroy a Dataset on Unity

March 23, 2016 - 1:53am #2


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).


For DataSets lodaded from file, you can simply deactivate and destroy the whole DataSet, using tracker.DestroyDataset( dataset, false );

Also, the fact that the Trackable IDs are not restarting from 0 (or from 1) is just because the internal ID counter is not necessarily reset to zero, but it's not necessarily an indication of a trackable not being removed from memory.



Log in or register to post comments