0

I am using the code below, it works if the bundle is installing the first time only, otherwise I am getting bundle already exist error. So my question is how can I check if the bundle exists and if so, read it from the cached file

    IEnumerator DownloadAndCache() {
    while(!Caching.ready)
        yield return null;

    using (WWW www = WWW .LoadFromCacheOrDownload(bundleURL, Version)) {
        yield return www;
        if (www .error != null)
        throw new UnityException("WWW Download had an error: " + www .error);
       // Must add check mechanism here

        AssetBundle bundle = www .assetBundle;
    //  bundle.Unload(false); this doesnt work
        if (AssetName == "") {
            mBundleInstance = Instantiate (bundle.mainAsset) as GameObject;
            mBundleInstance.transform.parent = cloudtarget.transform;
        }
        else {
            mBundleInstance = Instantiate(bundle.LoadAsset (AssetName)) as GameObject;
            mBundleInstance.transform.parent = cloudtarget.transform;
        }
    }
}

Thank you

firativerson
  • 435
  • 1
  • 4
  • 14
  • bundle.Unload (false); after else solved the error but I am redownloading it everytine, how could I fix this redownloading problem and load installed bundle from the cache – firativerson Sep 04 '16 at 16:20

1 Answers1

0

All the cached asset bundles are access by their names suppose , if name of your asset bundle is abc then use:

Caching.IsVersionCached(AssetBundleName, version) // AssetBundleName = "abc"

Remember one more thing that name what matters for example , if you download you asset bundle from http://somewibsite.com/AssetBundle/abc then all the domain part will be ignored and only name abc is saved as your asset bundle name.

Aryaman Gupta
  • 616
  • 1
  • 8
  • 20