So I know I probably can’t start a coroutine using a separate thread (if that’s even how you say it), but I would like to why this is not possible and if there is a way around this? Below is the code. (The code in a nutshell) I’m basically getting a direct link from firebase using the .GetDownloadUrlAsync() method than trying to download an asset bundle using a coroutine.
public void GetTargetOnFound(ImageTarget targetInfo)
{
string assetBundleName = "assetbundle";
string assetBundleEndpoint = _storageUrl + "/" + targetInfo.Name + "/" + assetBundleName;
StorageReference _Ref = _storage.GetReferenceFromUrl(assetBundleEndpoint);
_Ref.GetDownloadUrlAsync().ContinueWith((Task<Uri> task) =>
{
if (!task.IsFaulted && !task.IsCanceled)
{
StartCoroutine(HandleDownloadAssets(task.Result.AbsoluteUri, assetBundleName));
}
});
}
IEnumerator HandleDownloadAssets(string assetBundleEndpoint, string assetBundleName)
{
UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(assetBundleEndpoint);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
var prefab = bundle.LoadAsset<GameObject>(assetBundleName);
Instantiate(prefab, _imageTrackable.transform);
}
}
Any ideas? Thanks!