Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Downloading and Caching of Assetbundles

Discussion in 'Documentation' started by TimHeijden, May 15, 2016.

  1. TimHeijden

    TimHeijden

    Joined:
    Mar 5, 2015
    Posts:
    34
    Hello,

    I've been working on getting assetbundles to work in my game. Initially, I looked at the AssetBundleManager from Unity on the asset store but it was missing some crucial features. Thus I decided to go on an adventure and implement a manager myself. Sadly, I'm getting a bit confused by all the different possibilities that exist to download & cache these bundles.

    Downloading the bundles
    The manual provides an example to download bundles in its assetbundles section here. In this example, the WWW object is used.

    But when I look at UnityWebRequest, it claims that it "[..] is a replacement for Unity's original WWW object." It goes on to show some useful examples. Naturally, I figured I want to use this instead.

    Q1: Perhaps it is a good idea to change the documentation on asset bundles to use UnityWebRequest instead?

    Caching the bundles
    In caching, it becomes even more confusing for me. I know of 3 ways to check for cached bundles, of which the last one is particularly confusing to me:
    - Through WWW: WWW.loadFromCacheOrDownload
    - Through UnityWebRequest : DownloadHandlerAssetBundle (only when using version parameter)
    - Through Caching: Caching.IsVersionCached

    Q2: Does the Caching class ONLY work for the WWW object, or also for the (supposedly new & improved) UnityWebRequest?

    Q3: It looks like Caching is the only object with which you can check the version WITHOUT loading the assetbundle itself like the first 2 options, is this true?

    Q4: If Caching doesn't work for UnityWebRequest, is there any way to only do a version check with UnityWebRequest that I have missed?

    ps.
    I hope I put this in the right sub-forum, to me it feels like more of a documentation question rather than a technical one.
     
  2. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    The networking docs are overdue to be updated. I've logged Q1 in our system, it sounds like a good idea to get that example updated. Thanks! We should also think about updating the WWW class description to indicate that users should use UnityWebRequest instead. I don't know the answer to your last 3 questions, I'm sorry. I will ask.
     
  3. TimHeijden

    TimHeijden

    Joined:
    Mar 5, 2015
    Posts:
    34
    Thanks for the quick response. It looks like pretty much all the documentation is still only mentioning the WWW class. Right now I'm basically just experimenting to see what happens, which is a much slower process :)

    Another example, the SteamingAssets documention specifically states an issue with Android where you need to use the WWW class to extract data from a compressed .jar file.

    Can you give any indication as to when these docs will be updated, such as by the time 5.4 will come out of beta? I might just work on other things and wait with the implementation if that is the case.
     
  4. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    198
    I can't give you that, but it is high priority and pretty much next on my own task list.
     
  5. tcoursey

    tcoursey

    Joined:
    Mar 18, 2016
    Posts:
    6
    Did you get your assentBundle cached working? I'm very new to C# and Unity both and am having difficulty getting around an already loaded assetBundle with the same name issue. I'm trying to check the cache but using WebRequest it seems should be checking itself. Thanks for any ideas or samples either of you might have.
     
  6. TimHeijden

    TimHeijden

    Joined:
    Mar 5, 2015
    Posts:
    34
    I decided to put asset bundles on hold and worked on other projects. As you can see it looks like most of the documentation is still out of date :/
     
  7. Fotofobia

    Fotofobia

    Joined:
    Mar 31, 2017
    Posts:
    10
    Is there any way to cache the assetbundles I got from UnityWebRequest? I thought about serializing them but I am not sure if that will work...
     
  8. steven3Dim

    steven3Dim

    Joined:
    Feb 21, 2017
    Posts:
    12
    Yes, this works, it is already mentioned by the topic starter.

    This is how:
    Instead of calling:

    Code (CSharp):
    1. UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 0);
    You must call GetAssetBundle with a version number:

    Code (CSharp):
    1. UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 1, 0);
    See documentation here: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.GetAssetBundle.html

    You can also implement this with a call to 'new DownloadHandlerAssetBundle(string url, uint version, uint crc);'. See sample code here: https://docs.unity3d.com/ScriptReference/Networking.DownloadHandlerAssetBundle-ctor.html And documentation here: https://docs.unity3d.com/ScriptReference/Networking.DownloadHandlerAssetBundle-ctor.html

    Note that when you use caching, the 'request.responseCode' will no longer be value '200' (success), but will be '0', when the data is retrieved from cache!
     
  9. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    195