Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using OBB Expansion Files with Vuforia

Discussion in 'Editor & General Support' started by hollym16, Sep 29, 2014.

  1. hollym16

    hollym16

    Joined:
    Feb 21, 2013
    Posts:
    13
    This thread has been created to discuss ways of using OBB with Vuforia successfully.
    I have been working on this for a while with little success and am hoping to help not only myself but anyone else out there whose got the same problem.

    I have got the OBB files to work by following this tutorial: http://www.exoa.fr/tutorial-unity-4-apk-splitting-google-play-obb/#comment-180
    Which includes the Google OBB Downloader found here: http://u3d.as/content/unity-technologies/google-play-obb-downloader/2Qq

    With the new Google Developer console, you now have to publish your app to Alpha or Beta testing in order to test your app.

    So far so good for me, the OBB downloads and runs as it should. The problem comes when I get to my Augmented Reality scene: it initiates the tracker but nothing augments from it.

    I then did a lot of research on why this would happen and found out that the app doesn't read the dataset the same from the OBB as it normally does. This means that the dataset (.XML and .DAT files) needs to be extracted from the OBB and saved in a persistent data path in order to work properly.

    I found this script that is meant to extract the datasets:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.IO;
    4.  
    5. public class ObbExtractor : MonoBehaviour {
    6.    
    7.     void Start () {
    8.         StartCoroutine(ExtractObbDatasets());
    9.     }
    10.     private IEnumerator ExtractObbDatasets () {
    11.         string[] filesInOBB = {"Tracker_Name.dat", "Tracker_Name.xml"};
    12.         foreach (var filename in filesInOBB) {
    13.             string uri = "file://" + Application.streamingAssetsPath + "/QCAR/" + filename;
    14.            
    15.             string outputFilePath = Application.persistentDataPath + "/QCAR/" + filename;
    16.             if(!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
    17.                 Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
    18.            
    19.             var www = new WWW(uri);
    20.             yield return www;
    21.            
    22.             Save(www, outputFilePath);
    23.             yield return new WaitForEndOfFrame();
    24.         }
    25.     }
    26.     private void Save(WWW www, string outputPath) {
    27.         File.WriteAllBytes(outputPath, www.bytes);
    28.        
    29.         // Verify that the File has been actually stored
    30.         if(File.Exists(outputPath))
    31.             Debug.Log("File successfully saved at: " + outputPath);
    32.         else
    33.             Debug.Log("Failure!! - File does not exist at: " + outputPath);
    34.         Application.LoadLevel("SceneMenu1");
    35.     }
    36. }
    All looks good. I then uploaded the .APK and .OBB to Alpha on the Google Developer Console (this was not the first version I uploaded) waited for it to propagate, then tested it via one of my test accounts.
    This did not work, it still pushes to the AR Scene but augments nothing.

    I have tweaked loads of little bits in the hope of finding what the problem is but with little success.

    Has anyone got any ideas on this or been successful in created a working app with obb and vuforia?
     
  2. Lucas_Gaspar

    Lucas_Gaspar

    Joined:
    Sep 27, 2012
    Posts:
    5
    If the files are saved correctly then you just have to load the DataSet manually on the vuforia scene, here's an example script, just change the "mDataSetNames" for the DataSet you are using, also you need to deactivate or remove the "DatabaseLoadBehaviour" from the "ARCamera", the "WaitForSeconds" are optional

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Vuforia;
    4.  
    5. public class ARFix : MonoBehaviour
    6. {
    7.     private string[] mDataSetNames = new string[] {"Marinela", "MarinelaTatoo2015"};
    8.  
    9.     void Awake()
    10.     {
    11.         StartCoroutine (FindTrackerAndLoad());
    12.     }
    13.  
    14.     IEnumerator FindTrackerAndLoad()
    15.     {
    16.         ObjectTracker itracker = null;
    17.         while(itracker == null)
    18.         {
    19.             itracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
    20.             yield return null;
    21.         }
    22.         yield return new WaitForSeconds (0.2f);
    23.  
    24.         foreach(string datasetName in mDataSetNames)
    25.         {
    26.             DataSet dataSet = itracker.CreateDataSet();
    27.             yield return new WaitForSeconds (0.2f);
    28.             #if UNITY_ANDROID  && !UNITY_EDITOR
    29.             if(dataSet.Load (Application.persistentDataPath + "/QCAR/" + datasetName +".xml", VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
    30.             #else
    31.             if(dataSet.Load (datasetName))
    32.             #endif
    33.             {
    34.                 yield return new WaitForSeconds (0.2f);
    35.                 itracker.ActivateDataSet(dataSet);
    36.             }
    37.             yield return new WaitForSeconds (0.2f);
    38.         }
    39.     }
    40. }
     
  3. nicolas_J

    nicolas_J

    Joined:
    Sep 3, 2015
    Posts:
    1
    Hi Lucas_Gaspar...

    Im using both scripts to solve the vuforia trouble. My main scene contains the first script and i think it works fine extracting the files. But i have a doubt about this because when i check the persistent path on my android tablet, the size of the files are 0 bytes.... U think there is an extraction issue there?

    And then when i launch the augemented scene, the app just crush. any suggestion?

    Thanx for ur time.
     
  4. VirtualImmersive

    VirtualImmersive

    Joined:
    Dec 16, 2011
    Posts:
    31