question

sinjimonkey avatar image
sinjimonkey asked

Downloading Unity AssetBundles from PlayFab - getting null returned

I'm having trouble downloading the asset bundles I've uploaded to my CDN (If any admin checks this - it is for the project Augle)

After I've used GetContentDownloadUrlRequest I've then used Unity's UnityWebRequest with a DownloadHandlerAssetBundle handler. This throws no errors and returns null.

Frustratingly - I get the result when I use an invalid path as I do when I use a valid path. The path is the directory from the root in my File Madement tab, right? In this case 'Android/promo/nrwe'? I'm honestly a little surprised that sending an invalid string doesn't return any kind of error - neither with GetContentDownloadUrlRequet nor with the UnityWebRequest.

This is the code I'm calling with the results of the GetContentDownloadUrlRequest (where 'Key' is the path inside my File Manager - 'Android/promo/nrwe' - and deliver is a callback I intend to pass a scriptable object that is contained inside the AssetBundle... but I haven't gotten that far yet)

I will attach the code as the first comment (because clicking the 'code' button seems to turn the whole post into code, which is frustrating.

unity3d
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sinjimonkey avatar image sinjimonkey commented ·
IEnumerator downloadURLBundle(string url, string key, System.Action<ContentData> deliver) {

  UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(url, 0);
  DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(url, 0);
  request.downloadHandler = handler;
  Debug.Log("Sending URL request");
  //yield return 
  request.Send();
  while (!request.isNetworkError && request.downloadProgress < 1) {
  //Debug.Log(request.downloadProgress);
  yield return new WaitForSeconds(.1f);
  }
  Debug.Log("URL Request Returned");

  if (request.isNetworkError) {
  Debug.LogError(request.error);
  yield break;
  }

  //To load all assets
  AssetBundle bundle = handler.assetBundle;
  if (bundle == null) {
  Debug.Log("No bundle!?  "+key);
  } else {
  UnityEngine.Object[] assetObjectArray = bundle.LoadAllAssets();
  foreach (UnityEngine.Object obj in assetObjectArray) {
  Debug.Log("Loaded:  " + obj.name);
  //GameObject i = obj as GameObject;
  //theCurrentObject = Instantiate(i, this.transform);
  }
  }
0 Likes 0 ·

1 Answer

·
sinjimonkey avatar image
sinjimonkey answered

Nevermind - turns out I wasn't sending the device portion of the key (Android/) I had changed the key in the wrong portion of the code so it was actually looking in the wrong place.

Sometimes I have to ask the question to think about it a different way and then I resolve it on my own.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.