OBB Expansion and Vuforia Engine
While you are allowed to use the OBB split option with Vuforia, you should be aware that certain Vuforia functionalities may need to be handled in an alternate manner.
In particular, the database loading feature is affected as the dataset files (.dat and .xml) that were placed in the Assets/StreamingAssets/Vuforia folder of your Unity project will now be part of the .obb expansion file. As a consequence, the DataSet load methods of the Vuforia API will fail to locate and load those files.
Therefore, we advise to create a custom script that retrieves and copies the dataset files of your Vuforia Targets in a separate scene before your AR scene.
High level script behavior
The custom script should read your dataset .xml and .dat files from these locations:
- Application.streamingAssetsPath + "/Vuforia/" + dataset_xml_filename / dataset_dat_filename
- Application.applicationDataPath + ''/Android/obb/" + obb_filename (check the Android developer guide for more information on the actual OBB path and filename: Google Play Store – Expansion files).
Read the .dat and .xml files using the UnityWebRequest class with a
uri pointing to one of the locations above (see also https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html).
Get the file contents from the
UnityWebRequest class, using its DownloadHandler property.
This will save the content into a new pair of .dat and .xml files at a writable location on your device storage (e.g. your SD card, or otherwise to a device’s internal storage), or, store them onto a subdirectory of
- Application.persistentDataPath + "/MyDatasets/MyDataset.xml
- and Application.persistentDataPath + "/MyDatasets/MyDataset.dat")
Use the Vuforia API to load the databases from the new location, using the STORAGE_ABSOLUTE option.
For more information on dataset loading from an SD card, please refer to the ObjectTracker API Overview and Working with Vuforia Engine and Unity.
How to retrieve dataset files from the OBB expansion file
- Ensure that the desired databases are enabled in the Databases expandable menu under Vuforia Configuration.
NOTE: Databases are automatically added to the Databases list and will be loaded and activated as long as their TrackingBehaviour components are enabled.
- Navigate Build Settings and ensure that the build platform is set to Android.
- Continue to Player Settings -> Android Settings -> Other Settings.
- Set Write Permissions to External (SDCard).
- Under Publishing Settings, Check the Split Application Binary box.
- Create a new scene (in this example, it is named Vuforia-0-Splash) or make use of one of your scenes that is started before your Vuforia enabled scene.
- Add/position the scene in the Build Settings so that it is before your augmented reality scene(s).
- Create a GameObject in the scene and attach a new script to it with the name; ObbExtractor.cs.
- Copy the following code example and adjust it according to your databases and file paths.
This code snippet pulls the Astronaut .dat and .xml dataset files (assuming the default Image Target database was imported) from the .obb and outputs them in the application’s
persistentDataPath, allowing them to be automatically loaded once Vuforia is initialized.