Page 1 of 1

Saving AssetBundle

Posted: Wed Dec 25, 2019 11:51 pm
by BFRETHGIL
Is it possible to save the entire AssetBundle?
When my user gets to level 100 - I load new pics and characters, so the user download it from the assetbundle

Code: Select all

AssetBundle myLoadedAssetBundle = AssetBundle.LoadFromFile(@"C:\ab\level100Assets");
Sprite newSprite = myLoadedAssetBundle.LoadAsset<Sprite>("Assets//pic1.jpg");
....
But when my app restarted my user re download it again , and I want to download it only ONCE,
so I was wondering if I can just save the entire assetBundle on file and check if exist for the next time?
1. Is it going to save it uncompressed? (is it even recommended to save it? Or gonna take a lot of space?)
2. What's the difference between saving it with ES3 to saving it with Unity Load and Store AssetBundle in Cache (which is a bit more complicated than Easy Save)

Thanks

Re: Saving AssetBundle

Posted: Fri Dec 27, 2019 11:56 am
by Joel
Hi there,

If you have access to the AssetBundle file as a byte array, you can save it to a local file using ES3.SaveRaw(bytes, filePath).

If you have a path to the AssetBundle, which it seems like you do in your example, you can get the bytes of the file using ES3.LoadRaw(filePath). Note that you will still need to save and load from the AssetBundle using the AssetBundle API.

This will save it uncompressed, though as far as I'm aware AssetBundles already have compression applied (they're essentially a zip file) so applying further compression would do nothing.

Cached AssetBundles are presumably stored in memory, whereas Easy Save stored data to file. However, as this is part of Unity's API you would need to contact them for more info on this.

All the best,
Joel

Re: Saving AssetBundle

Posted: Fri Dec 27, 2019 7:47 pm
by BFRETHGIL
Yes I download the AssetBundle from a path (right now path is my computer, later will be some online storage)

How do I save it raw? This is my command to download the assetbundle:
AssetBundle myLoadedAssetBundle = AssetBundle.LoadFromFile(@"C:\ab\level100Assets");
I get an myLoadedAssetBundle object that I can extract from it all my files (using AssetBundle API of course), how do I save it?
Also, do you think it's a good idea?

P.S. I don't see ES3.LoadRaw, just ES3.LoadRawBytes

Re: Saving AssetBundle

Posted: Sun Dec 29, 2019 9:40 am
by Joel
Hi there,

If you will be downloading it from online in the future, you will presumably be using a UnityWebRequest to do so. In which case, you can save the downloaded bytes to a local file using ES3.SaveRaw(request.downloadHandler.data, "myFile.es3"). This will store the data in Application.persistentDataPath, which is the only place guaranteed to be writable at runtime and persist between updates.

Just to clarify, ES3.LoadRawBytes is the ES3.LoadRaw method you require if you want to load an existing local file as a byte array.

All the best,
Joel