title: Dynamically Load and Activate a dataset (vuforia and unity)
body: <p>I want to make a system that I can use to download various targets dynamically from my website without using "Cloud" system.
  I also want to save the dataset to .xml and .dat formats which I want to activate from my saving device. </p>
  
  <p>There are a lot of methods and pages to doing that with vuforia and unity, but unfortunately when I test it I receive an error for all of them.
  It seems that i have made a mistake in my code or a vuforia class was changed.</p>
  
  <p>For instance please look this link:
  <a href="https://developer.vuforia.com/library/articles/Solution/Unity-Load-DataSet-from-SD-Card" rel="nofollow">https://developer.vuforia.com/library/articles/Solution/Unity-Load-DataSet-from-SD-Card</a>
  I got Error: Using Vuforia;</p>
  
  <p>I placed the .xml and .dat files in "Application.persistentDataPath + "/" + "Building1.xml"
  i used this Script "DataSetLoadBehavior" that attached "AR Camera and placed my code in it. I got an Error:</p>
  
  <blockquote>
    <p>NullReferenceException: Object reference not set to an instance of an
    object DataSetLoadBehaviour.OnInitialized () (at Assets/Qualcomm
    Augmented Reality/Scripts/DataSetLoadBehaviour.cs:49)
    DataSetLoadBehaviour.Start () (at Assets/Qualcomm Augmented
    Reality/Scripts/DataSetLoadBehaviour.cs:80)</p>
  </blockquote>
  
  <p>My code is this:</p>
  
  <p>unity 4.2 pro and vuforia 2.8.9 or 3.0.9</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>/*==============================================================================
  Copyright (c) 2010-2014 Qualcomm Connected Experiences, Inc.
  All Rights Reserved.
  Confidential and Proprietary - Qualcomm Connected Experiences, Inc.
  ==============================================================================*/
  
  using System.Collections.Generic;
  using UnityEngine;
  
  /// &lt;summary&gt;
  /// This behaviour allows to automatically load and activate one or more DataSet on startup
  /// &lt;/summary&gt;
  public class DataSetLoadBehaviour : DataSetLoadAbstractBehaviour
  {
         [HideInInspector, SerializeField]
         public List&lt;string&gt; mDataSetsToActivate2 = new List&lt;string&gt;();
        [SerializeField, HideInInspector]
      public List&lt;string&gt; mDataSetsToLoad2 = new List&lt;string&gt;();
  
      protected DataSetLoadBehaviour()
      {
      }
      private void OnDestroy()
      {
          QCARAbstractBehaviour behaviour = (QCARAbstractBehaviour) UnityEngine.Object.FindObjectOfType(typeof(QCARAbstractBehaviour));
          if (behaviour != null)
          {
  
          }
      }
  
      public void OnInitialized()
      {
  
          if (QCARRuntimeUtilities.IsQCAREnabled())
          {
              foreach (string str in this.mDataSetsToLoad2)
              {
  
                  if (!DataSet.Exists(str, QCARUnity.StorageType.STORAGE_ABSOLUTE))
  
                  {
                      Debug.LogError("Data set " + str + " does not exist.");
                  }
                  else
                  {
  
                      ImageTracker tracker = TrackerManager.Instance.GetTracker&lt;ImageTracker&gt;();
                      DataSet dataSet = tracker.CreateDataSet();
                      if (!dataSet.Load(str))
                      {
                          Debug.LogError("Failed to load data set " + str + ".");
                      }
                      else if (this.mDataSetsToActivate2.Contains(str))
                      {
                          tracker.ActivateDataSet(dataSet);
                      }
                  }
              }
          }
      }
  
      public void OnTrackablesUpdated()
      {
      }
  
      private void Start()
      {
  
          QCARAbstractBehaviour behaviour = (QCARAbstractBehaviour) UnityEngine.Object.FindObjectOfType(typeof(QCARAbstractBehaviour));
          if (behaviour != null)
          {
  
  
              mDataSetsToLoad2.Add(Application.persistentDataPath + "/" + "Building1.xml");
  
  
  
  
              OnInitialized();
          }
      }
      public override void AddOSSpecificExternalDatasetSearchDirs()
      {
  #if UNITY_ANDROID
          if (Application.platform == RuntimePlatform.Android)
          {
              // Get the external storage directory
              AndroidJavaClass jclassEnvironment = new AndroidJavaClass("android.os.Environment");
              AndroidJavaObject jobjFile = jclassEnvironment.CallStatic&lt;AndroidJavaObject&gt;("getExternalStorageDirectory");
              string externalStorageDirectory = jobjFile.Call&lt;string&gt;("getAbsolutePath");
  
              // Get the package name
              AndroidJavaObject jobjActivity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic&lt;AndroidJavaObject&gt;("currentActivity");
              string packageName = jobjActivity.Call&lt;string&gt;("getPackageName");
  
              // Add some best practice search directories
              //
              // Assumes just Vufroria datasets extracted to the files directory
              AddExternalDatasetSearchDir(externalStorageDirectory + "/Android/data/" + packageName + "/files/");
              // Assume entire StreamingAssets dir is extracted here and our datasets are in the "QCAR" directory
              AddExternalDatasetSearchDir(externalStorageDirectory + "/Android/data/" + packageName + "/files/QCAR/");
          }
  #endif //UNITY_ANDROID
      }
  
      void Update()
      {
  
      }
  
  }
  </code></pre>