- Home /
obb apk scene load fail
Due to large file size, i have split chosen to "Split Application Binary" to facilitate upload to play store. Unity creates 2 files, apk and obb and installation goes through when the option "Build and Run" is selected. Loading the 1st scene after the splash screens fails and the app hangs at this point.
I have seen many people face this issue and there are multiple solutions like manually renaming the obb file, or writing code to load the obb etc.
However i feel that this should be handled by Unity because it did the splitting for me. Infact i tried multiple approaches suggested online but none worked.
Hence i would like to know whats the latest steps to do to get this working.
Unity Version: 2018.2.3f1 Android: Nougat (>7)
Answer by misher · Oct 31, 2018 at 02:08 PM
Make sure your first scene is included in apk and not in obb. If your first scene is big one, make new small scene for loading. Also there are problems for Vuforia traking configurations, they are automatically included to obb file and then Vuforia fails to load them, here is workaround, make sure to run it in your starting scene:
using System.IO;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ObbExtractor : MonoBehaviour
{
[SerializeField]
string[] filesInOBB;
void Start()
{
#if UNITY_ANDROID
StartCoroutine(ExtractObbDatasets());
#endif
}
private IEnumerator ExtractObbDatasets()
{
foreach (var filename in filesInOBB)
{
string uri = Application.streamingAssetsPath + "/Vuforia/" + filename;
string outputFilePath = Application.persistentDataPath + "/Vuforia/" + filename;
if (!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath));
var www = new WWW(uri);
yield return www;
Save(www, outputFilePath);
yield return new WaitForEndOfFrame();
}
}
private void Save(WWW www, string outputPath)
{
File.WriteAllBytes(outputPath, www.bytes );
// Verify that the File has been actually stored
if (File.Exists(outputPath))
{
Debug.Log("File successfully saved at: " + outputPath);
}
else
{
Debug.Log("Failure!! - File does not exist at: " + outputPath);
}
}
}
Your answer
Follow this Question
Related Questions
Android Apk + Obb Splitting | Scene is not loading 3 Answers
Load Scene by audio clip 2 Answers
Load Different Stages 1 Answer