[AssetBundles] - Cannot load assetbundle from URL a second time - Even after unload - URGENT

Hi all,

I am looking for some urgent advice/help regarding asset bundle LoadFromCacheOrDownload.
UnloadAssetBundle is called on a button click in the UI.
loadedAssetBundle is a member variable of class that has the functions.

The following are the steps I take :

  1. LoadFromCacheOrDownload(URL, 0) ← Get a WWW download with assetbundle from the web.
  2. The above is successfull the first time. I check the IsVersionCached → Returns TRUE.
  3. Call Unload(false) on the asset bundle then destroy the object.
  4. Try LoadFromCacheOrDownload(URL, 0) again with the same asset bundle.
  5. Get the error → Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle.

See code below :

private AssetBundle loadedAssetBundle;
public IEnumerator DownloadAtURL(string assetName, string URL)
    {

        Debug.Log("PRE ASSET CACHED = " + Caching.IsVersionCached(assetName, 0));
        Debug.Log("Downloading using -> WWW.LoadFromCacheOrDownLoad");

        var www = WWW.LoadFromCacheOrDownload(URL, 0);
        yield return www;
        if(!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(www.error);
            yield return null;
        }
   
        Debug.Log("Finished downloading assetbundle");
        Debug.Log("POST ASSET CACHED = " + Caching.IsVersionCached(assetName, 0));

        loadedAssetBundle = www.assetBundle;
    }

    public void LoadAssetBundle()
    {
        Debug.Log("Loading all assets for bundle " + loadedAssetBundle.name);
        loadedAssetBundle.LoadAllAssets();
    }

    public void UnloadAssetBundle()
    {
        Debug.Log("Unloading asset bundle " + loadedAssetBundle.name);
        loadedAssetBundle.Unload(true);
        Destroy(loadedAssetBundle);
    }

See output below :

Download Asset

POST : https://55AE.playfabapi.com/Client/GetContentDownloadUrl

Get content download URL for asset : 1/Windows/Windows result : https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA

Downloading 1/Windows/Windows from https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA

PRE ASSET CACHED = False
Downloading using -> WWW.LoadFromCacheOrDownLoad
starting www download: https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA
https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA cached to C:/Users/Peter/AppData/LocalLow/Unity/WebPlayer/Cache/InfinityPlusTwo_puzzleverse/26d9c28d789c254f71ea99a3463b99a7ccc2f4fa
----- Total AssetImport time: 0.065631s, AssetImport time: 0.000000s, Asset hashing: 0.000000s [0 B, 0.000000 mb/s]

loading from cache: https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065963&Signature=oJa3DBfiDyRyE2hHix~Wpm1VqLrfoBzLTvlbTlf2RjPGtcwVAJj1y6ms9gp102GLAd7FAT2d-VCpSFKRAXLUPD04tor4j7znLl7EWQqi6TgEyBeLwBp3XY8D69S8gD4EJFH3V54hUVNZmk0nRCKBp4pJqnph4y4-DcChuCiIx0U_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA
Finished downloading assetbundle
POST ASSET CACHED = True
Unloading asset bundle

Download Asset

POST : https://55AE.playfabapi.com/Client/GetContentDownloadUrl

Get content download URL for asset : 1/Windows/Windows result : https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065979&Signature=eLuGatsAj0-yGDjltOWYIQjBf~4oNtGFlvOcXhacjt0InZjLotfyWPAHAWW64j3UH06sTYfeC9OGmmOjTD~WkkYSLgu5qpLtad6e~DF-cYj3jiK~fblZMEKsTAqhlb3m8~ZnaHqfsFS9~PGjoipUTNHvMy0Yh0JKYwwpa~N3B0Y_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA

Downloading 1/Windows/Windows from https://cdn.playfab.com/55ae/etc/1/Windows/Windows?Expires=1438065979&Signature=eLuGatsAj0-yGDjltOWYIQjBf~4oNtGFlvOcXhacjt0InZjLotfyWPAHAWW64j3UH06sTYfeC9OGmmOjTD~WkkYSLgu5qpLtad6e~DF-cYj3jiK~fblZMEKsTAqhlb3m8~ZnaHqfsFS9~PGjoipUTNHvMy0Yh0JKYwwpa~N3B0Y_&Key-Pair-Id=APKAIOVJ4VBNZZU4TTQA
PRE ASSET CACHED = True
Downloading using -> WWW.LoadFromCacheOrDownLoad

You are trying to load data from a www stream which had the following error when downloading.
Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle.
UnityEngine.WWW:get_assetBundle()

[C:/buildslave/unity/build/Runtime/Misc/WWWCached.cpp line 265]
(Filename: Assets/sdk/scripts/TestBedController_Dev.cs Line: 357)

WWWCached data can only be accessed using the assetBundle property!
WWWCached data can only be accessed using the assetBundle property!
WWWCached data can only be accessed using the assetBundle property!
WWWCached data can only be accessed using the assetBundle property!
You are trying to load data from a www stream which had the following error when downloading.

Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle.
WWWCached data can only be accessed using the assetBundle property!
WWWCached data can only be accessed using the assetBundle property!
WWWCached data can only be accessed using the assetBundle property!

Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle.

Finished downloading assetbundle

POST ASSET CACHED = True
You are trying to load data from a www stream which had the following error when downloading.
Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle.

Any ideas why UNLOAD is not working ?! Seems like a bug in unity, not sure what else I can do here.
Would be most appreciated and thanks in advance.

Take a look at the docs to make sure you have not missed anything: http://docs.unity3d.com/Manual/keepingtrackofloadedassetbundles.html
If you still think this is a bug then report it and we can investigate it further: Unity QA: Building quality with passion

I am having the same problem but only on WP8, all other platforms work(webplayer, android, ios).

1 Like

Thanks Karl,

Yes, I had a look at that and as you can see the code is doing the exact same thing but only taking a single AssetBundle instance into account.

Vincent thinks this could be a bug, have raised the issue → (Case 715850)

I created this as a test after having issues with adapating Vincent Zhings AssetBundleManager to using versions instead of hashes.

I seem to have gotten it to work using hashes from the AssetBundleManifest, loading the manifest file using WWW then referencing all other asset bundles using the hash from it. Also, the IsVersionCached is no longer relevant when using Hash’s.

Using versions causes all kinds of strangeness when working with asset bundle dependencies and the manifest.

As soon as I switched back to using LoadFromCacheOrDownload with Hash’s it all worked fine.

I thought it better to use versions as I needed to create my own hash table and lookup file for updating assets using a CDN online.

Regards,
Peter