Log in or register to post comments

Change the Image Target runtime

July 23, 2013 - 8:26am #1

Hi Guys, i have a problem with the imageTargetBehaviour,

I have created a a dataset with two image targets, activated the dataset in the DataSetLoadBehaviour and attached a script that listen witch one of the two imagetargets is actually in front of the camera.

Everything works fine but whean i attach an ImageTarget prefab in the ImageTargetBehaviour i have to decide witch one have to augmentated.

Is there a way to define it runtime?

if image one or image two is in fornt of the camera the DefaultTrackableBehaviour calls the function onTrackingFound, thaen i just have to load some contents from an xml.

Thank everybody


Change the Image Target runtime

February 8, 2018 - 8:47pm #17


 i am a beginner

How can I start learning Unity fast?

pls send unity examples 


Change the Image Target runtime

November 29, 2016 - 12:09am #16

hi,how did you get it?

Change the Image Target runtime

December 14, 2015 - 6:51am #15


the easiest way is to attach all models to your image target and inactivate all of them except the first one, and then by clicking button , inactivate the first one and activate the second one and so on.


Change the Image Target runtime

December 14, 2015 - 6:40am #14

This is my scenario:

I have some 50 3D models created. I need to switch between them in runtime. The entire scene should be like I once focus the TargetImage, it should augment say model no.1. I want all other models to appear one after the other in AR itself. Is there a way I can do it?


model A, model B , model C is created

1. I use stones as the target image and focus to it, I see model A getting augmented.

2. I create a button saying next model.

3. I click on it and model B should get augmented.

4. I again click on next scene, model C gets augmented.

Note: I will not focus on Stones Image Target again and again. I do it only once!

Is it possible to realise the above said thing? I need to do this ASAP. Any help would in this regard will hughly be appreciated

Change the Image Target runtime

August 22, 2014 - 1:32am #13

sorry i encunter another problem. first i try to deactivate or destroy a dataset but, once again  i want to load and activate them dataset.exist will return me a false, i try to put my dataset in StreamingAssets/QCAR but it still gives me false value, in addition my storage type will gice error of requested item is unloaded.  here is my code




 ImageTracker imagetracker = TrackerManager.Instance.GetTracker<ImageTracker> () as ImageTracker;

        System.Collections.Generic.IEnumerable <DataSet> data =     imagetracker.GetDataSets ();
        foreach (DataSet da in data) {


        if (status == true) {
            LoadDataSet ("money", DataSet.StorageType.STORAGE_ABSOLUTE);
                } else
            if (status == false)
                        LoadDataSet ("StonesAndChips", DataSet.StorageType.STORAGE_ABSOLUTE);


    private bool LoadDataSet(string dataSetPath, DataSet.StorageType storageType)
        // Check if the data set exists at the given path.
        if (!DataSet.Exists(dataSetPath,storageType))
            Debug.LogError("Data set " + dataSetPath + " does not exist.");
            return false;
        // Request an ImageTracker instance from the TrackerManager.
        ImageTracker imageTracker =
        // Create a new empty data set.
        DataSet dataSet = imageTracker.CreateDataSet();
        // Load the data set from the given path.
        if (!dataSet.Load(dataSetPath, storageType))
            Debug.LogError("Failed to load data set " + dataSetPath + ".");
            return false;
        // (Optional) Activate the data set.
        return true;
    private bool DestroyDataSet(DataSet dataSet)
        // Request an ImageTracker instance from the TrackerManager.
        ImageTracker imageTracker =
        // Make sure the data set is not active.
    bool success= imageTracker.DeactivateDataSet(dataSet);
        // Destroy the data set
        // (choose true to also destroy the Target objects that belong to the data set).
        bool success = imageTracker.DestroyDataSet(dataSet, true);
        return success;




Change the Image Target runtime

August 20, 2014 - 6:38pm #12

thank for your answer.


Change the Image Target runtime

August 20, 2014 - 2:50am #11

Actually i don't think that you can use more then 100 targets also swapping the datasets, i'm not sure of that but i remember that i had read that in some vuforia specs.. for your case you should use a clouddatabase...

The logic it works is the one i wrote before, it creates a number of new game objects that is a rapresentations of the number of targets inside the dataset. In my experience you can't create just one imagetarget for each dataset and then swap the targets to look for, once you activate a dataset if it contains 5 targets it will create 5 new game objects that you can control throught your DefaultTrackableEventHandler, for example imagine that you have 5 different cubes to be shows corrispondly of every target, for each cube you can create a prefab that is stored in the resources folder, Vuforia says to you wich image the AR camera is tracking, in your DefaultTrackableEventHandler you can control that, so for example in your DefaultTrackableEventHandler you say at the system that if the AR camera is tracking the target called one it has to initialize the prefab number one has a child of the new game object that is associated to that target, you can change it size, position and rotation to be placed in the right position and you can destry it while the tracking is lost.


Change the Image Target runtime

August 20, 2014 - 2:10am #10

thank for your reply.

i think, i got really understand it now, just the case i have so many data which are more than 100 targets, so i need 165 databases and each contain 5 targets ,in addition i need to detect the targets are belongs to which database and do some action accordingly. actually, i dont want to create an image target for each target. i want to create an image target for each dataset rather than each target and then trigger between targets at run time.


in addition, by scripting the below code under AR camera , shall i create my DefaultTrackableEventHandler version to keep the tracks? like what u said . sorry i really confuse on that, i know its a stupid question



Change the Image Target runtime

August 20, 2014 - 1:52am #9

Sorry i don't understand why you need 165 datasets, i mean, every dataset is a collection of targets (images that can be recognized) why do you need so many?

Basically you can activate more than one dataset attached to the AR camera, you can do that through unity interface or runtime but this is an action that need an action(click for example) to be done.

To control the imagetarget instances runtime you do not need to put an image target prefab in the hierarchy and assign to it a dataset and target.

When you have a dataset active, at startup vuforia creates a number of new game objects that is the number of the targets that are contained inside all the datasets that are active, every newgame object is an imagetarget object with attached the imagetargetbehaviour script, that means that every newgameobject already have inside the informations about which image they have to look for.

Whith the method that i wrote before every time the ar camera recognize an image it attach to that a scrpt that you use to control the events associated to that script, so in this way you can know that the AR camera has recognized the image number 3 for example and trough a series of conditions you can attach to the image number 3 a series of actions and graphics that you already had prepared, in my case i use prefabs to be attached and destroyed realtime.

In this way the system is lighter.

Change the Image Target runtime

August 19, 2014 - 7:17pm #8

thanks, it is really helpful.

what i actually mean is that, in the image target object, under image target behaviour, i need 165 dataset and 5 image target, and i need all them to be detectable at run time. so i think there is need of 165 image target object to be created and each bound to one dataset and then the 5 image target under each data set need to be swapable and checked at run time. so basically i need to change the image target behaviour under image target object. is that possible ? or is that any other way to be implemented ?

or shall i change DefaultTrackableEventHandler to check each 5 image target under each data set one by one ?

note :

total step would be like this:

step 1: create 165 image target objects

step 2: assign a data set to each of image target objects

step 3: check the  5 targets under each data set one by one and get the track. 




thanks for your help , appriciate.

Change the Image Target runtime

August 19, 2014 - 4:50am #7

Hello, i don't understand exactly what you mean, if you want to activate and attach a dataset on runtime to the AR cmera there's a method well documented on the Vuforia documentation, if you want instead activated the dataset from the visual interface of Unity and you want control the image target generated on runtime the method is different.

When a Dataset is initialized it creates automatically the instances of the targets inside the dataset, if you want to control them realtime you have to attach at the instances of the imagetarget a scrpt, usually i attach a script to the AR camera like this:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System;

public class TargetLister : MonoBehaviour {

    public TextAsset textXML;
    public string name;

    // Use this for initialization
    void Start () {
    // Update is called once per frame
    void Update ()
        StateManager sm = TrackerManager.Instance.GetStateManager();
        IEnumerable<TrackableBehaviourtbs = sm.GetActiveTrackableBehaviours();
        foreach(TrackableBehaviour tb in tbs)
                name = tb.TrackableName;

                ImageTarget it = tb.Trackable as ImageTarget;
                Vector2 size = it.GetSize ();

                XmlDocument xml = new XmlDocument();
                GameObject go = tb.gameObject;

                if (go.GetComponent<FucineBehaviour>() == null) {
                // Add a Trackable event handler to the Trackable.
                // This Behaviour handles Trackable lost/found callbacks.
                go.active = true;
                XmlNode nodo = xml.SelectSingleNode("//Target[@id=\"" + name + "\"]");
                go.GetComponent<FucineBehaviour>().infos = nodo;

                else {
//                Debug.Log ("ATTIVO GO");
//                go.active = true;




The important part is the UPDATE function, when a target is activated this script attach to it a new script called FucineBehaviour that actually is our version of the DefaultTrackableEventHandler, throught this script and the use of XML i can control realtime all the events that are connected to a specific instance of a target....


You can already find good examples and documentation on the Vuforia website..

Hope that i was helpfull....

Change the Image Target runtime

August 18, 2014 - 11:44pm #6

may i know how to  create and send an instance of dataset and send it to AttachContentToTrackables(DataSet dataSet) method.


thanks , sorry for stupid question, iam newbie here.


Change the Image Target runtime

July 24, 2013 - 8:50am #5

Got it!

Thank you

Change the Image Target runtime

July 23, 2013 - 1:37pm #4

You don't need to set the ImageTarget for the objects that are created by this method. They are already defined as such by the TrackableBehaviours recognized by the TrackerManager's StateManager.

You can determine which target from the Database the objects represent by checking the TrackableBehaviour's  .TrackableName ( see: https://developer.vuforia.com/resources/api/unity/class_trackable_behaviour )



// Add Trackable event handler and content (cubes) to the Targets.
 private void AttachContentToTrackables(DataSet dataSet)
     // get all current TrackableBehaviours
     IEnumerable<TrackableBehaviour> trackableBehaviours =
     // Loop over all TrackableBehaviours.
     foreach (TrackableBehaviour trackableBehaviour in trackableBehaviours)
         // check if the Trackable of the current Behaviour is part of this dataset
         if (dataSet.Contains(trackableBehaviour.Trackable))
             GameObject go = trackableBehaviour.gameObject;
             // Add a Trackable event handler to the Trackable.
             // This Behaviour handles Trackable lost/found callbacks.
             // Create a cube object.
             GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
             // Attach the cube to the Trackable and make sure it has a proper size.
             cube.transform.parent = trackableBehaviour.transform;
             cube.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
             cube.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f);
             cube.transform.localRotation = Quaternion.identity;
             cube.active = true;
             trackableBehaviour.gameObject.active = true;


Change the Image Target runtime

July 23, 2013 - 10:17am #3

Hi Alessandro,

thank you for the fast answer,

i was trying to use the technique illustrated in the swappable device databases, i hafe a few questions:

I have created a new script component attached to the AR camera, is it right??

it seems to work fine becouse it creates two new game objects with the ImageTargetBehaviour script active when i launch the application, but how can i set the  DataSet and ImageTarget variables on each gameobject so that they can augment the right image (they are empty)?

Sorry, i'm a newbe and a little bit confused.

Thank you





Log in or register to post comments