Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

check if LoadSceneAsync() failed

Discussion in 'Addressables' started by OneManArmy3D, Jun 23, 2020.

  1. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
    How can we check if loading scene via Addressables.LoadSceneAsync() failed (in WebGL)?
    I tried OperationException != null and if Status == AsyncOperationStatus.Failed

    Addressables version 1.13.1
    Unity 2019.4.6f1
     
    Last edited: Aug 4, 2020
  2. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
  3. dogboydog

    dogboydog

    Joined:
    Nov 23, 2012
    Posts:
    53
    Hi,

    What happens if you check those two that you tried? There was an error but if you check those fields it seems like there's not? Can you post a code snippet where you're starting the async operation and checking if it failed?

    There's also yourOperation.Task.isFaulted and yourOperation.Task.Exception
     
  4. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
    Multithreaded operation (at this moment) are not supported on WebGL.

    Code (CSharp):
    1.     void Start(){  
    2.         Addressables.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive).Completed += OnSceneLoaded;
    3.     }
    4.  
    5.     void OnSceneLoaded(AsyncOperationHandle<SceneInstance> obj)
    6.     {
    7.  
    8.         if (obj.OperationException != null)
    9.             Debug.Log("Exception");
    10.  
    11.         if (obj.Status == AsyncOperationStatus.Failed)
    12.             Debug.Log("Failed");
    13.      
    14.         if (obj.Status == AsyncOperationStatus.Succeeded)
    15.         {
    16.             Debug.Log("Succeeded");
    17.             obj.Result.ActivateAsync();
    18.         }
    19.         else
    20.         {
    21.             Debug.LogError("Failed to load scene at address: " + sceneToLoad);
    22.         }
    23.     }
     
    Last edited: Jul 25, 2020
  5. dogboydog

    dogboydog

    Joined:
    Nov 23, 2012
    Posts:
    53
    Okay so what happens when you run this? It says succeeded, but then you see an error later?
     
  6. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
    actually OnSceneLoaded() is not even called.

    Errors in console:
    * Asset Bundle download is complete, but no data have been received
    * Exception encountered in operation Resource<IAssetBundleResource>(************.bundle): RemoteAssetBundleProvider unable to load from url file:///***********.bundle, result='Unknown Error'.
    * Scene '*******.unity' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
    * ArgumentNullException: Value cannot be null. Parameter name: _unity_self

    I will try another way.
     
    Last edited: Jul 25, 2020
  7. dogboydog

    dogboydog

    Joined:
    Nov 23, 2012
    Posts:
    53
    Oh oh right. Thanks for clarifying. That makes sense, maybe the "Completed" callbacks are only called on success.

    You can try something like this:

    Code (CSharp):
    1.  
    2. void Start(){
    3.         StartCoroutine(LoadScene());
    4.     }
    5.  
    6.     IEnumerator LoadScene()
    7.     {
    8.         var obj = Addressables.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive);
    9.  
    10.        
    11.         yield return obj;
    12.  
    13.         if (obj.OperationException != null)
    14.             Debug.Log("Exception");
    15.         if (obj.Status == AsyncOperationStatus.Failed)
    16.             Debug.Log("Failed");
    17.    
    18.         if (obj.Status == AsyncOperationStatus.Succeeded)
    19.         {
    20.             Debug.Log("Succeeded");
    21.             obj.Result.ActivateAsync();
    22.         }
    23.         else
    24.         {
    25.             Debug.LogError("Failed to load scene at address: " + sceneToLoad);
    26.         }
    27.     }
     
  8. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
    Now i tried:

    Code (CSharp):
    1.     IEnumerator    DownloadMapNew(){
    2.         var loadAsync = Addressables.LoadSceneAsync(sceneToLoad, LoadSceneMode.Additive);
    3.    
    4.         while (!loadAsync.IsDone)
    5.         {
    6.             Debug.Log(loadAsync.PercentComplete);
    7.             yield return null;
    8.         }
    9.  
    10.         if (loadAsync.OperationException != null)
    11.             Debug.LogWarning("Exception");
    12.         else Debug.LogWarning("NULL");
    13.  
    14.         if (loadAsync.Status == AsyncOperationStatus.Failed)
    15.             Debug.LogWarning("Failed");
    16.         else Debug.LogWarning("Succeeded");
    17.     }
    and in console was:
    0.75
    0.5
    0.725
    and errors (like above).
     
  9. dogboydog

    dogboydog

    Joined:
    Nov 23, 2012
    Posts:
    53
    So the initial problem of not being able to check if it failed or not is solved now by using an IEnumerator, but you're still getting the errors from Addressables. I haven't used the download functionality so I'm not sure. Maybe someone from Addressables can chime in
     
  10. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189
    "it failed or not is solved now by using an IEnumerator"
    solved? I still can't check if map was successfully loaded.
    All i see in browser console is errors.
     
  11. OneManArmy3D

    OneManArmy3D

    Joined:
    Jun 2, 2011
    Posts:
    189