Search Unity

UnityWebRequestAssetBundle.GetAssetBundle is not recommended for local files, why?

Discussion in 'Asset Bundles' started by FranClip, Jan 14, 2021.

  1. FranClip

    FranClip

    Joined:
    Feb 27, 2020
    Posts:
    10
    Quoting from the asset bundles documentation ( https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html )
    "Note, that while you can use this API to load Asset Bundle from local storage (using file:// URI or jar:file// on Android), this is not recommended, use AssetBundle.LoadFromFileAsync instead."
    But this doesn't explain why isn't recommended. Is it performance related?
    I mean, isn't this the "way" to load asset bundles using disk cache?
     
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    353
    If you download a bundle thats already on the filesystem, would it not then be duplicated and therefor utilise two times the amount of disk space?

    As in, lets say I have a bundle in streaming assets which I load via the GetAssetbundle unitywebrequest. I'm guessing it now exists twice, once in cache and once in the streaming assets folder.
     
  3. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    You are correct, it will exist in the streaming assets folder and it also be uncompressed on the asset bundle cache
     
    nilsdr likes this.
  4. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    353
    Unless, I suppose, you don't pass in a hash or version number. According to the documentation that will skip the caching mechanism entirely.
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,028
    Correct, if you specify only the path/URI, asset bundle will be loaded, but not cached.

    Loading asset bundles using AssetBundle.LoadFromFileAsync ir more efficient than using UnityWebRequest, that's why it is discouraged.
     
  6. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    Even after it's cached? (So on the second call to UnityWebRequest)
     
    FranClip likes this.
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,028
    If it's cached using built-in caching system, then that is how you load a bundle from cache - do the same UnityWebRequest.
    The discouragement is specifically for local asset bundle files. If file is local and you don't use caching, then by using UWR you are simply paying extra price for nothing.
     
    nilsdr likes this.
unityunity