Jan
22
2017

Load AssetBundles with Caching

Small sample script to load assetbundles.

Features:
– It first loads bundle hash from the manifest file on server
– Then uses that hash string as asset bundle loader parameter (to use cached version if available, see docs)
– Instantiate gameobject after loading

source:
https://github.com/UnityCommunity/UnityLibrary/blob/master/Scripts/AssetBundles/AssetBundleLoader.cs

 


3 Comments + Add Comment

  • Great post, great script, thanks!

    I have a question.
    Why do you use random url parameter in line 84?

    www = UnityWebRequest.GetAssetBundle(bundleURL + “?r=” + (Random.value * 9999999), hashString, 0);

    I would expect it would cause redownloading of the asset no matter if it is cached or not, maybe I am wrong.

    Tomasz

    • yeah, it was added to avoid getting cached bundle information from server, but my understanding was that if the hashString is supplied, it wouldn’t load the whole bundle again (if its locally cached already).

      Never actually measured or checked if that’s true.. : D

Leave a comment

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.