I'm making a game for webgl. But when i upload the assetbundles on the link and then loading it in the game it show error.
error: Failed to decompress data for the AssetBundle 'Memory'. UnityEngine.WWW:get_assetBundle()
NullReferenceException: Object reference not set to an instance of an object DownloadScript+d__2.MoveNext () (at Assets/DownloadScript.cs:27)
When i load asset from my system(local), it load it perfectly. But when i upload it on a live link it is not loading it.
This is my code to load it from server
'''
public class DownloadScript : MonoBehaviour
{
public string url;
// Start is called before the first frame update
[System.Obsolete]
void Start()
{
StartCoroutine(DownloadModel());
}
[System.Obsolete]
IEnumerator DownloadModel()
{
WWW wwws = new WWW(url);
yield return wwws;
//UnityWebRequest www = UnityWebRequest.GetAssetBundle();
//yield return www.SendWebRequest();
AssetBundle assetBundle = wwws.assetBundle;
Instantiate(assetBundle.LoadAsset("cube"));
}
'''
Code to load from local system:
'''
AssetBundle myLoadedAssetbundle;
public string path;
public string bundleAsset;
void Start()
{
LoadAssetBundle(path);
//InstantiateObjectFromBundle(bundleAsset);
StartCoroutine(DownloadAndCache(path));
}
void LoadAssetBundle(string bundleUrl)
{
myLoadedAssetbundle = AssetBundle.LoadFromFile(bundleUrl);
//myLoadedAssetbundle = AssetBundle.
Debug.Log(myLoadedAssetbundle == null ? "Failed to load AssetBundle" : "AssetBundle Succesfully Loaded");
}
void InstantiateObjectFromBundle(string assetName)
{
var prefab = myLoadedAssetbundle.LoadAsset(assetName);
Instantiate(prefab);
}
'''