I’m starting to develop the whole “asset bundle management” thing. And I already caught several doubts.
My user is supposed to choose from a list any level he wishes. If that level exists, download, load and play it. The documentation doesn’t seem to cover the entire process, that’s why I have doubts on how to proceed.
What I got so far:
public class AssetBundleWebLoader : MonoBehaviour
{
IEnumerator LoadBundle(string bundleUrl, string assetName)
{
using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(bundleUrl))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
// Is this correct to check if the download is complete?
if (www.downloadProgress >= 1.0f)
{
//bundle.LoadAllAssets(); // Perhaps don't load EVERYTHING here.
}
}
}
}
}
Download a bundle from a URL. Fine.
On the last line, I am downloading the bundle. How do I check if the bundle has been fully downloaded so I can deploy it?
Can I let the user keep the bundle in memory so he doesn’t have to download it again after he reboots the game? How?
If the bundle consists in a single scene, every 3D object, material and stuff will be included in the bundle. EXCEPT for scripts that were not included in the original build. Am I correct?
If I mark a folder as Asset Bundle, will everything inside become part of the bundle?
I think I will add more questions the more I work on it.
When you “yield return www.SendWebRequest()” it will stop the coroutine until the download is complete. The only bit that remains is fully integrating and loading the asset bundle, which happens when you get a reference to it. Just check that returned AssetBundle is not null.
Not in memory but on disk.
AssetBundle system has buitin caching system. Check the documentation for UnityWebRequestAssetBundle.GetAssetBundle, the overload you currently use does not cache and will download every time, but there are overloads with more parameters that will download once and load from cache next time.
Scripts are compiled and shipped with your game, you can’t include them in asset bundles.
This is the part in the documentation I don’t understand. Because:
public static Networking.UnityWebRequest GetAssetBundle(string uri, uint version, uint crc);
Look like WWW.LoadFromCacheOrDownload: check if it is in the cache, if it is not, download it. But, as far as I understand, it goes in the cache. Will it be deleted on the next reboot?
public static Networking.UnityWebRequest GetAssetBundle(string uri, CachedAssetBundle cachedAssetBundle, uint crc);
Is the same but you are allowed to specify a cache path. Again, deleted on the reboot?