0
IEnumerator WWWLoader()
{
    WWW bundleRequest = new WWW("*****************");
    while(!bundleRequest.isDone)
    {
        yield return null;
    }

    AssetBundle bundle = null;
    if (bundleRequest.bytesDownloaded > 0)
    {
        AssetBundleCreateRequest myRequest = AssetBundle.LoadFromMemoryAsync(bundleRequest.bytes);
        while(!myRequest.isDone)
        {
            Debug.Log("loading....");
            yield return null;
        }
        if (myRequest.assetBundle != null)
        {
            bundle = myRequest.assetBundle;
            GameObject model = null;
            if (bundle != null)
            {
                AssetBundleRequest newRequest = bundle.LoadAssetAsync<GameObject>("Log");
                while (!newRequest.isDone)
                {
                    Debug.Log("loading ASSET....");
                    yield return null;
                }
                model = (GameObject)newRequest.asset;

                bundle.Unload(false);
            }
        }
        else
        {
            Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL (assetBundle = null)");
        }
    }
    else
    {
        Debug.LogError("COULDN'T DOWNLOAD ASSET BUNDLE FROM URL (0 bytes)");
    }
}

This is my code to load an AssetBundle (I've removed the URL). It gives me the error "Failed to decompress data for the AssetBundle 'Memory'." I'm not sure if 'Memory' is referring to the AssetBundle name because mine is called 'log' so is it referring to a problem with memory? Any help on understanding this error and fixing it is much appreciated.

Jahill
  • 78
  • 1
  • 7
  • 1
    in general the [`WWW`](https://docs.unity3d.com/ScriptReference/WWW.html) is **obsolete** ... have you tried rather using [`UnityWebRequestAssetBundle.GetAssetBundle`](https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html) ? – derHugo Jun 16 '21 at 14:10
  • Yes, I'm getting a different problem though. AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www); results in bundle = null. – Jahill Jun 16 '21 at 15:15
  • As a person that had been using WWW for quite a while and struggled to make the transition to UnityWebRequest, I have to suggest for you to start using that. Much more robust and convinient once you get through the learning process. – Rhach Jun 23 '21 at 06:31

3 Answers3

0

I believe your issue related to the compression being used when the bundles are built. You may need to use LoadFromMemoryAsync instead. https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromMemoryAsync.html

raybarrera
  • 160
  • 1
  • 10
0

So, I have gotten past the error by using UnityWebRequestAssetBundle as shown here (recommended by derHugo).

I was initially using a simple FTP server to access the assets and it would not allow me to download them (from Unity, but in a browser it worked fine). I then switched to using a Flask server, which worked like a charm.

JeanLuc
  • 4,783
  • 1
  • 33
  • 47
Jahill
  • 78
  • 1
  • 7
0

Note to people finding this like I did; if you're using Asset Bundles for webgl, you need to make sure the assetbundles are uncompressed (BuildAssetBundleOptions.UncompressedAssetBundle). Docs mention it but it can be easy to miss, and the default is LZMA.