Search Unity

Save AssetBundle after LoadFromFile has been called? Takes too long each time.

Discussion in 'Asset Bundles' started by juliens137, Jan 25, 2020.

  1. juliens137

    juliens137

    Joined:
    Oct 2, 2017
    Posts:
    26
    Hi,

    I have an app that delivers Sessions of VR experiences to a user's iPhone. We distribute multiple worlds through on demand resources. Currently a user downloads the asset bundle through on demand resources and then Unity runs AssetBundle.LoadFromFile() to load the asset bundle and then it launches the scene. The assetbundles only contain scenes. This step takes a while compared to before when we shipped the app with the content already installed.

    I am wondering if there is a way to save the asset bundle in a way that I won't have to call LoadFromFile() each time. Or is there a way to do that in a more efficient manner? The loading time is an issue and since the async operation .progress and .isDone don't work there's not even a way to show a loading bar (Let me know if you have a solution to that as well lol)

    Thanks!
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    This comes down to two things.
    One is AssetBundle compression. Play around with that (when building bundle) to get the most efficient one.
    Other is that you can load that bundle using UnityWebRequest and emply Unitys built-in caching system. This will recompress the bundle on first load and store result to cache, every next load it will take the bundle from cache.
     
  3. juliens137

    juliens137

    Joined:
    Oct 2, 2017
    Posts:
    26
    Thanks for the repsonse!

    I am using on demand resources currently to distribute the assetbundles. Is there a way to cache the bundles after they are loaded the first time, similarly to how the UnityWebRequest method would do it?

    Also do you know if there are plans to fix the .isDone and .progress fields for the AsyncOperations? Can't understand how I can give users loading feedback without them.

    Thanks
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    I believe UnityWebRequest is the only way to use built-in cache system. Note, that it can load local files via file:// URI, not only download them from the internet.
     
  5. juliens137

    juliens137

    Joined:
    Oct 2, 2017
    Posts:
    26
    Thank you for the response. That is good to know that you can load from local files. Will the cached memory be purged? How can I check whether the cache is still there or will it check automatically and recreate assetbundle if it's not? I tried something similar in the past but couldn't get it to load from odr resource paths. Is there a requirement for where the files can be stored?
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735