On a project I’m working on at the moment we’ve been told to host the obb the unity generates from a split build on our own servers instead of supplying it via google as you normally would.
To this end, we’re trying to write a downloader that will download the obb, save it in the same place as it would normally save (normally we use the asset GitHub - Over17/UnityOBBDownloader: This is Unity plugin for Android, intended to download .obb expansion files from Google Play. that I think most people end up using for this download).
Currently the obb downloads just fine from our server and saves to disk apparently without issue. However the second I try to load a scene from the obb, we see the error.
“Level “main” (1) couldn’t be loaded because it has not been added to the build settings.”
Now i’m confused as it says 1 instead of the normal -1 for this error. But primarily here my issue is why is this happening? I’m certain that we the apk and the obb are from the same build so its not that. Is there something else special that we should be doing when downloading the obb from our own servers?
Thanks for any ideas on this one.
EDIT:
Ok it seems that the obb will load scenes, but only when the app has restarted. It seems that unity only mounts the obb file on start, and (based on the way the normal “from-google” downloader works) on resume as well.
Currently my thinking is to create a blank android activity that i can simply activate, and complete immediately to trigger this resume behaviour but that sounds ugly as all hell. Wondering if anyone is aware of a way to force unity to try and remount the obb without needing to do a suspend/resume or restart?
@FatWednesday: Hello ,I have managed to sort it till exactly where you got stucked, my obb downloads 100 % and then it crashes…
I am sharing that part of the code below:
if (www.error != null)
{
log ("wwww error " + www.error);
percentageValue.value = 0;
}
else
{
Debug.Log("obb download" + www.data);
Debug.Log("obb downloaded ? " + www.isDone);
Debug.Log("obb download size " + www.bytesDownloaded);
System.IO.Directory.CreateDirectory(GooglePlayDownloader.GetExpansionFilePath());
Debug.Log("About to create directory");
string futureFile = GooglePlayDownloader.GetMainOBBPath_ifNoExist(expPath);
Debug.Log("About to create file " + futureFile);
var bytes = www.bytes;
AssetBundle bundle = www.assetBundle;
Debug.Log("obb size " + www.bytes);
if (bytes != null)
{
System.IO.File.WriteAllBytes(Application.dataPath + futureFile, bytes);
Debug.Log("bytes file created" + futureFile);
}
checkPath ();
}
yield return new WaitForSeconds(0.1f);
if (www.error != null)
{
log ("wwww error " + www.error);
percentageValue.value = 0;
GameLoader.gameloaderInstance.DownloadingMsgLabel.text = "Please connect to the Internet and try again.";
GameLoader.gameloaderInstance.ErrorIconSprite.SetActive(true);
GameLoader.gameloaderInstance.WifiIconSprite.SetActive(false);
GameLoader.gameloaderInstance.DownloadingMsgLabel.color = ErrormsgLabelColor;
}
else
{
PlayerPrefs.SetInt ("OBB", 1);
GameLoader.gameloaderInstance.SceenLoadingSprite.SetActive (true);
Debug.Log ("Calloing the Game Scene");
Application.LoadLevelAsync(1);
}
void OnApplicationPause()
{
Debug.Log ("ON Paused Called");
}
private IEnumerator checkPath()
{
while (true)
{
Debug.Log ("Application.dataPath" + Application.dataPath);
yield return new WaitForSeconds (0.2f);
}
}