Hi all,
I’m trying to download, unpack and use an Asset Bundle from a server, but I get the following error:
Error while downloading Asset Bundle: Failed to decompress data for the AssetBundle “https://addressname.it/test/assetbundleprova.unitypackage”
If I try to do the same but with the Asset Bundle saved in a local folder, then it works perfectly.
Here is the code I’m using (took from this Unity guide [5.6 DRAFT] Asset Bundles Documentation - Google Docs):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class DownloadAssetBundles : MonoBehaviour {
public Button download;
private string assetBundleName = "assetbundleprova.unitypackage";
private void Start() {
download.onClick.AddListener(() => StartCoroutine(InstantiateObject()));
}
private IEnumerator InstantiateObject() {
string uri = "https://addressname.it/test/" + assetBundleName;
Debug.Log("uri: " + uri);
UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 0);
yield return request.Send();
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(request);
GameObject sphere = bundle.LoadAsset<GameObject>("SphereProva");
GameObject obj = Instantiate(sphere);
obj.transform.position = new Vector3(0, 0, 0);
}
}
How could I resolve this? I found other answers to similar questions but they didn’t fit my needs.
Thanks in advance and have a nice day!