- Home /
AssetBundle.Unload(false)
I had a previous discussion in regards to Unloading asset bundles after downloading them. In the reply Lucas had mentioned that it is always a good idea to unload the bundles to free up memory. However, I am a bit confused when it comes to scenes that reside in asset bundles. For instance, see the below code snippet. If I unload the asset bundle after loading the scene, I assume that the asset bundle will be removed from memory and the scene is still in memory. However, this is not the cause. Unloading the asset bundle seems to be unloading the entire scenes contents. Based on the documentation for Unload, passing a value of false to it indicates that this behavior should not be occuring??? Am I missing something here?
public IEnumerator LoadScene() { WWW stream = new WWW("assetBundles/dynamicScene.unity3d");
yield return stream;
AssetBundle bundle = stream.assetBundle;
// Load a scene that was stored in the asset bundle.
Application.LoadLevelAdditive("dynamicScene");
// This will cause everything in the scene to be unloaded.
bundle.Unload(false);
}
Answer by Joachim Ante · Sep 26, 2010 at 06:01 PM
The issue is that Application.LoadLevelAdditive is delayed until the next frame. Thus you are actually unloading before the level has been loaded.
You can add a yield between LoadLevelAdditive and Unload, then it should work. Better use LoadLevelAdditiveAsync and yield the result.
Answer by Dreamora · Aug 15, 2010 at 12:09 AM
Report a bug with a small sample.
While loadleveladditive does not technically load the scene as a scene but add it into the current one, instantiated stuff should be kept alive too and does so if you instantiate it directly or if you used loadlevel there
I had happen to just copy and past some code I was experimenting. But it doesn't matter if the level is loaded additively or non additively. The same behavior occurs. From my own research, scenes in asset bundles tend to work slightly differently then regular assets when loading and unloading. I'm not sure if this was by design or not. However, I had a discussion with them about this in the unity 3.0 alpha mailing list back in $$anonymous$$ay, so they are aware of the problem.