- Home /
Why am I losing all scene data when loading an Asset Bundle-loaded scene?
I'm working a Unity iOS pro project where we make use of asset bundles. I dynamically download the asset bundle which defines an entire scene. I currently use the following procedures to load in an asset bundled scene which seemed to work in Unity 3.5.1, but doesn't work for me anymore (I get a completely empty scene) after I upgraded to Unity 3.5.2:
public IEnumerator DownloadLevelBundle(int levelId, int versionNumber = 1)
{
WWW download;
string downloadUrl = ...; //omitted
Debug.Log("About to download " + downloadUrl + " ...");
//download = new WWW (downloadUrl);
download = WWW.LoadFromCacheOrDownload (downloadUrl, versionNumber);
yield return download;
if(download.error != null)
{
Debug.Log(download.error);
return false;
}
Debug.Log("Level downloaded");
AssetBundle assetBundle = download.assetBundle;
if (assetBundle != null)
{
Application.LoadLevel("main"); // the scene file is called 'main'
Debug.Log("Waiting for end of frame...");
yield return new WaitForEndOfFrame();
Debug.Log("Frame ended");
assetBundle.Unload(false); // only free the scene after the frame has ended
}
else
Debug.Log("Couldnt load resource");
}
When I had previously encountered this issue, I figured it was due to the fact that Application.LoadLevel defers loading the objects until the next frame, hence I added in the frame yield. This no longer does the trick though.
Oddly enough, if I do TWO next frame yields, all my scene data appears, but the entire Unity IDE crashes when I stop playing.
Any ideas of what I need to do to a) get the scene to appear, and b) not have Unity IDE crash when I stop playing the scene?
Thanks in advance, Jason
Did you resolve this problem? Could you help me? I have the same problem. $$anonymous$$y Unity IDE crashes when I stop playing but my scene data never appear. Thanks.
I have this problem even without unloading any assets at all. After loading a scene from an asset bundle, Unity crashes when I stop playing.
Your answer
Follow this Question
Related Questions
Crash with iOS Build 2 Answers
Webplayer hangs on loading scene 2 Answers
ArgumentOutOfRangeException when calling CrashReport.reports 0 Answers
EXC_BAD_ACCESS when rotating the device in iOS simulator 0 Answers