Log in or register to post comments

activate and deactivate fails

July 3, 2013 - 1:42am #1

Trying to isolate an issue and I ran into this...I can't seem to activate and deactivate a locally saved dataset. I took the code from the swappable device databases page, but couldn't make it work. For one, I found that if I specified a storage type, no matter which one, it would report that the dataset didn't exist (it does). If you omit a storage type then that part works.

It appears that activation works, but then deactivation reports an error. In the console it says it couldn't deactivate, but actually the 3d content is gone so it looks like it did do something. In the Unity inspector I can see that the imagetarget for it is still moving around, but the models that are sitting on it are not being drawn. But then if you try to reactivate it, it claims to be found and tracking, but the content isn't there. I'm guessing the pseudo failed deactivation put something in a weird state.

Anyway I tried to make a very short test case of this so I could understand how to make it work, and I can't. 

using UnityEngine;
using System.Collections;

public class TestDataSets : MonoBehaviour {
	
	private string MyDataSet = "SomeDataSetGoesHere";
	
	private void activate()
	{
		ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
		DataSet dataSet = imageTracker.CreateDataSet();
		dataSet.Load(MyDataSet);
	    imageTracker.ActivateDataSet(dataSet);
	} 
	
	private void deactivate()
	{
		ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
		DataSet dataSet = imageTracker.CreateDataSet();
		dataSet.Load(MyDataSet);
		imageTracker.DeactivateDataSet(dataSet);
	} 
}

Those two methods are called from the pressing of 2 seperate buttons. I need to get to the point where I can repeatedly press them over and over to activate and deactivate a local (bundled) dataset.

activate and deactivate fails

July 3, 2013 - 5:12am #4

Great - glad to hear !

 

N

activate and deactivate fails

July 3, 2013 - 4:52am #3

That works!

My issue was that I couldn't figure out how to get a handle on the right data to call deactivate on. I glanced through the samples available, but erroneously assumed there was nothing of interest (to the problem i was having) in the imagetarget sample because of the name. Whoops.

activate and deactivate fails

July 3, 2013 - 2:01am #2

Can you please look at the ImageTargetsMenu.cs script that comes with the Image Targets sample application?

This shows the code that gets executed to switch between the two datasets, covers activation/deactivation and should be error free.

 

N

 

 

if(GUI.Button(new Rect(0,Screen.height/2 - 30, Screen.width, 114), mDatasetText, itemButtonStyle)){

    

    ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

 

    IEnumerable<DataSet> dataSets = imageTracker.GetDataSets();

    IEnumerable<DataSet> activeDataSets = imageTracker.GetActiveDataSets();

 

    // Changes current active dataset

    if (dataSets.Count() >= 2 && activeDataSets.Count() >= 1)

    {

        DataSet activeDataSet = activeDataSets.ElementAt(0);

        

        if(mCurrentDataSetIndex == 0)

        {

            imageTracker.DeactivateDataSet(activeDataSet);

            imageTracker.ActivateDataSet(dataSets.ElementAt(1));

            mCurrentDataSetIndex = 1;

            mDatasetText = SWITCH_TO_STONES_AND_CHIPS;

            

        }else

        {

            imageTracker.DeactivateDataSet(activeDataSet);

            imageTracker.ActivateDataSet(dataSets.ElementAt(0));

            mCurrentDataSetIndex = 0;

            mDatasetText = SWITCH_TO_TARMAC_TEXT;

            

        }

        

    }

    else

    {

        Debug.LogWarning("Not enough data sets to toggle");

    }

    

    mMenuOpen = false;

    mButtonPressed = true;

    

}

 

 

 

Log in or register to post comments