- Home /
Loading assets for a level from asset bundle
Hi,
I'm trying to build unity player as small as possible, so I decided to put all assets into a asset bundle and keep only levels with scripts in main application.
I have successfully created both application and bundle, but I'm stuck on loading only required assets for a single level.
What I'm doing now is loading all assets from bundle at application startup and mark them by DontDestroyOnLoad, so they are kept in memory when a level is loaded. While this is hardly final solution, I'm looking how to load only assets needed for a particular level, preferably without much hassle.
So I'm looking for a way how load a level and let Unity to load and instantiate required assets from asset bundle, just as they were part of the application.
Is this possible? Or do I need to do it a hard way? (i.e. to generate list of required assets and manage their loading and unloading manually for example)
Thanks in advance!
Answer by Ashkan_gc · Mar 15, 2011 at 01:11 PM
first of all if you load something from asset bundle you can cache it in new versions and even without caching they will remain in browser's cache at least in current session so redownload will not happen and you don't need to keep track of them.
why don't you use streamed web players? just check the box called streamed in web player build and then unity will load levels one by one with their required assets. you can load downloaded levels and let the user play the game while downloading next levels. it's easy and is exactly what you want. at first all headers/scripts/ will be downloaded with the first scene assets. then the player starts playing while downloading second scene and so on.
if you are using a platform other than web player unfortunately there is not an easy way to do that. you should create an asset bundle of all required assets in a level and use AssetBundle.LoadAll to load them all when download is complete.
Thanks for tip Ashkan, unfortunately I'm doing it for android, so streamed web player is out of question.
ok i added a way to make it possible for none web players to load it all easily. not as easy as that but easy.
Thanks Ashkan, although this is exatly waht I would prefere to avoid, I may give it a try.
Is it really easy to obtain list of all assets for a level? Do you know how to do that?
currently i don't remember but if you could find a way to get the surely it's easy. just select the scene file and create the asset bundle from it and tell it to include all dependencies. boom, it will collect them all. i tested more than a year ago with my unity pro trial but after buying unity never i needed it.
Your answer
Follow this Question
Related Questions
Loading game objects dinamycaly 1 Answer
Asset creator in Unity 2 Answers
Asset bundle mismatch in different Unity version 1 Answer
Dynamically expanding existing Level by adding "Sub-Levels" 1 Answer
AssetBundles between Levels 1 Answer