Search Unity

Bug WebRequestAsyncOperation.completed lies to me on iOS?

Discussion in 'Asset Bundles' started by brownboot67, Apr 17, 2023.

  1. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    I have a pretty straightforward Bundle Manager that loads my AssetBundles as needed. I mostly rely on the various callbacks to move individual WebRequests through their steps to completion. This works fine on Android and Win.

    However, on iOS when the UnityWebRequestAsyncOperation.completed fires DownloadHandlerAssetBundle.GetContent(theWebRequest) returns the following console error:

    InvalidOperationException: Cannot get content from an unfinished UnityWebRequest object.


    Here is some paraphrase code to give you a more clear idea...

    Code (CSharp):
    1. public virtual void Load()
    2.         {
    3.             InitializeWebRequest(_bundlePath);
    4.             BeginWebRequest();
    5.         }
    6.  
    7.         protected void InitializeWebRequest(string path)
    8.         {
    9.             _webRequest = UnityWebRequestAssetBundle.GetAssetBundle(path, Hash);
    10.             _bundleHandler = new DownloadHandlerAssetBundle(path, Hash, 0);
    11.             _webRequest.downloadHandler = _bundleHandler;
    12.         }
    13.  
    14.         protected void BeginWebRequest()
    15.         {
    16.             _bundleOperation = _webRequest.SendWebRequest();
    17.             _bundleOperation.completed += WebRequestComplete;
    18.         }
    19.  
    20.         protected virtual void WebRequestComplete(AsyncOperation op)
    21.         {
    22.             _bundleOperation.completed -= WebRequestComplete;
    23.  
    24.            //Error happens here but only on iOS...
    25.             _bundle = DownloadHandlerAssetBundle.GetContent(_webRequest);
    26.             if (_bundle != null)
    27.             {
    28.                 _bundleRequest = _bundle.LoadAllAssetsAsync();
    29.                 _bundleRequest.completed += LoadCompleteInternal;
    30.             }
    31.         }
    Any ideas?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Looks like a bug. Could you report it?
     
  3. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Only if you promise to confirm this one in less than 2 months.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    If you don't report it, it will surely take more than 2 months ;)
     
  5. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Lol, I know. It's been reported! Hopefully its just something I'm doing.