Saving AssetBundle

Discussion and help for Easy Save 3
Post Reply
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Saving AssetBundle

Post 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
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving AssetBundle

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
BFRETHGIL
Posts: 23
Joined: Wed Jun 13, 2018 8:25 pm

Re: Saving AssetBundle

Post 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
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving AssetBundle

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply