- Home /
Unity 5 Asset bundle unloading problem
Hello, While I'm loading asset bundles without www.assetBundle.Unload(false); everything is ok on iPad Air 2, but on iPad with 1GB there is problem with memory(unexpected close), because I have big scene and a lot of assets. While I'm loading asset bundles with: www.assetBundle.Unload(false); Assets aren't loaded. What can I do? I created one asset bundle per one asset, because I need this in project.
I've been wrestling with the similar problems lately. It really seems like putting scenes into asset bundles is not encouraged or at least has some downsides / unresolved problems, judging by the way the system works. Yet putting scenes into asset bundles would be the natural solution when your game is heavily scene/level based and you have over a hundred of them and need to add more.
Few of the issues I've encountered are:
1) assetBundle.LoadAsset("scene")
returns null and just creates some kind of magical scene object into the application's scene list that can be loaded with Application.LoadLevel("scene")
ONLY before you call assetBundle.Unload();
(just like the OP said). When dealing with other assets you can unload the bundle as long as you have a reference to the objects you want to instantiate later. This is not possible with scenes.
2) Scene asset bundles seem to take a lot of space when cached to disk. I admit this might be project specific but to me it seems astounding that in our project we can bundle up 150 scenes into 20 asset bundles (130$$anonymous$$b combined) to cut 30$$anonymous$$b off of the build size, but once those 20 bundles are cached to the device, the installation size goes up from 100 $$anonymous$$b to 2Gb (!!)
The cached size goes down considerably when you use less bundles as does the combined bundle size (makes you think there's some redundant info in the bundles), but because of issue 1), you can't use just a few huge bundles or you'll run out of memory when loading your scene from one.
3) AssetDataBase.LoadAssetAtPath() doesn't work with scenes so it's impossible to establish a transparent system where when working in the editor, you'd use the resources straight from AssetDataBase using `AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName() ins$$anonymous$$d of bundles. This forces poeple to have the physical bundles whenever they work on the project and possibly commit these big binary files to version control, which is not cool.
4) I'm still investigating this but it seems loading scenes from bundles might be leaking memory. I do call www.Dispose() and assetBundle.Unload(false) after the level is loaded and they are not needed, and i do null the references to them so GC should take care of the rest, but If i load the same level over and over again, i still lose a considerable amount of memory with each loading.
Here's a good post about some of the problems. I read it way earlier but I didn't remember it mentions most of the problems I posted (and e.g. explains the bundle bloating) since i have run into those problems after i read it...
Your answer
Follow this Question
Related Questions
why UnloadUnusedAssets doesn't unload a asset? 0 Answers
Destroy single asset from AssetBundle 2 Answers
Build assetbundle successfully but cannot instantiate it 0 Answers
Asset Bundle Limitations 0 Answers
Assetsbundle in subfolder 0 Answers