Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug LoadSceneAsync is returning errors after last addressable package 1.21.17 update

Discussion in 'Addressables' started by cengage-jsal, Sep 1, 2023.

  1. cengage-jsal

    cengage-jsal

    Joined:
    May 10, 2022
    Posts:
    27
    Hi everyone,

    After updating the addressable package to version 1.21.17, Addressable.LoadSceneAsync() has been throwing two errors in our recent WebGL builds which we never encountered before.

    • "Scene 'Assets/Scenes/WiringDiagrams/WiringBasic2014.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"

    The issue begins to occur after our bootstrap and main menu scenes are loaded and initialized. When a new scene is selected from the main menu, LoadSceneAsync() returns those error messages. None of the selectable scenes can load correctly.

    I've tracked the problem down to the async op handle being returned from LoadSceneAsync(). It's never assigned to operationHandle because the errors are triggered before then.

    Code (CSharp):
    1.     IEnumerator QueueScene( string scene, bool additive )
    2.     {
    3.         if (!loadingScene)
    4.         {
    5.             loadingScene = true;
    6.    
    7.             yield return new WaitUntil( () => SceneManager.sceneCount == 1 && clearToLoad );
    8.    
    9.             operationHandle = Addressables.LoadSceneAsync( scene, additive ? LoadSceneMode.Additive : LoadSceneMode.Single, true );
    10.    
    11.             currentScene = SceneManager.GetSceneAt( SceneManager.sceneCount - 1 ).buildIndex;
    12.             currentSceneName = SceneManager.GetSceneAt( SceneManager.sceneCount - 1 ).name;
    13.             clearToLoad = false;
    14.             loadingScene = false;
    15.    
    16.             try
    17.             {
    18.                 StartCoroutine(WaitAndSetSceneActive( operationHandle ));
    19.             }
    20.             catch (Exception e)
    21.             {
    22.                 Debug.Log($"Failed to Load Scene: {currentSceneName}\nError Exception: {e}");
    23.             }
    24.             finally
    25.             {
    26.                 Debug.Log($"{currentSceneName} has successfully loaded.");
    27.             }
    28.         }
    29.     }
    I've also confirmed that related scene bundles are downloaded and cached in the browser cache before invoking LoadSceneAsync(). Also, the codebase has mostly remained unchanged before the package update and everything still works when playing in the editor.

    I've attempted a few solutions to fix the error (some of which were from this forum for similar errors) but to no avail.

    I'm not trying to suggest the new package has a regression, it's more likely some bad code/race condition on our end :) But I'm having a difficult time fixing this. How do I go about "revalidating" the operationHandle object is what I want to know.

    Any guidance or help would be awesome. If any more info is needed, please let me know. Thanks in advance.

    Our project is built with Unity 2022.3.5.f1.
     
  2. Bod9001

    Bod9001

    Joined:
    Jan 15, 2020
    Posts:
    3
    ok, looking through the code it looks like they've changed
    Addressables.DownloadDependenciesAsync(Assets.InternalId)
    to only download the bundle now, it doesn't load them automatically, can't tell if this is intentional or not
    currently working out how to manually tell it to load the bundle
     
    cengage-jsal likes this.
  3. Bod9001

    Bod9001

    Joined:
    Jan 15, 2020
    Posts:
    3
    so
    Code (CSharp):
    1.                     if (!(m_ProvideHandle.Location is DownloadOnlyLocation))
    2.                     {
    3.                         // this loads the bundle into memory which we don't want to do with download only bundles
    4.                         m_AssetBundle = downloadHandler.assetBundle;
    5.                     }
    from the source code
    DownloadOnlyLocation inherits from LocationWrapper, and there's no other classes that inherit from it,
    and nothing makes a new instance of LocationWrapper so there is physically no option to actually load it in when finished downloading , there might be some way of doing this but Documentation is 0,
    probably the best thing to do is going to
    UnityProject\Packages\manifest.json
    "disableProjectUpdate": true, add at the beginning before "dependencies" : {
    and rollback to addressables
    "com.unity.addressables": "1.19.19"
    there might be newer versions you can use that doesn't have this bug
     
    mcbauer and cengage-jsal like this.
  4. cengage-jsal

    cengage-jsal

    Joined:
    May 10, 2022
    Posts:
    27
    Thank you for the response. Interesting find... I'll run some tests and try to verify the bundle loading behavior your describing in my project.

    Unfortunately I can't roll back the addressable package because it will re-introduce this editor bug that 1.21.17 included the fix for.

    Maybe someone from the addressable team (@davidla_unity or @pillakirsten) can chime in with further guidance on this...
     
  5. cengage-jsal

    cengage-jsal

    Joined:
    May 10, 2022
    Posts:
    27
  6. HECer

    HECer

    Joined:
    Mar 17, 2013
    Posts:
    47
    bump
     
    cengage-jsal likes this.
  7. FdenUijl

    FdenUijl

    Joined:
    Sep 5, 2019
    Posts:
    32
    We also have this issue. Bump.
     
    cengage-jsal likes this.
  8. alexu

    alexu

    Joined:
    Jun 19, 2014
    Posts:
    8
    Same issue.
     
    cengage-jsal likes this.
  9. alan10801

    alan10801

    Joined:
    Sep 20, 2019
    Posts:
    5
  10. cengage-jsal

    cengage-jsal

    Joined:
    May 10, 2022
    Posts:
    27
    Just wanted to give an update on this issue:

    I was able to solve part of the error by doing what other people suggested in these threads:

    In summary, you must release the operation handle used for DownloadDependencies before invoking LoadSceneAsync. That operation handle for DownloadDependencies has a lock on the bundle data until it is properly released.

    However, once I added Release to our custom bundle controller, I was still getting the same error, but it would only trigger with the last scene bundle that was required to download.

    Our project is setup to download and load several scene bundles after a user selects a scene from the main menu. These scene bundles include the scene the user selected, and other helper scenes that are all loaded in additively. while debugging, I noticed that LoadSceneAsync was being called before the final bundle finished downloading.


    This was resolved by adding a yield that waited until all bundles were downloaded and their handles were released. After that change, LoadSceneAsync worked, and our scenes loaded!

    I'm not sure why but it seems like the bundles were taking longer to download... either way this thread can be closed.
     
    Claytonious and dan_soqqle like this.
  11. djexstas9

    djexstas9

    Joined:
    Mar 26, 2019
    Posts:
    12
    Having the same issue but with downloading sprites and text assets and trying to use them afterwards. Custom logs say asset was completely downloaded and ready to use but LoadAssetAsync results in an exception:
    "Unable to load dependent bundle from location e"
    where "e" is the first symbol of the assert guid.

    It also repros when building addresasbles localy and selecting "Use existing build (Android)" (also need to start a Hosting Service with local hosting and etc)

    Magically fixes by itself on second app start

    It started to repro after update unity to 2022.3.16 and addressables to 1.21.19. Before update we were using unity 2021.3.27 and addressables 1.21.2, this setup worked fine (at least didn't have this issue)
     
    Last edited: Jan 10, 2024
    gamelarson and cengage-jsal like this.
  12. gamelarson

    gamelarson

    Joined:
    Jul 25, 2020
    Posts:
    1
    Hi,
    I had the same problem. In Android build, the assets did not load with the same error message "Unable to load dependent bundle from location~". Then I realized I did not release the download handle (when I called
    DownloadDependenciesAsync). So I added a single line
    Code (CSharp):
    1. Addressables.Release(_downloadHandle);
    and everything was fixed. I am not sure how relevant this solution is to your specific case, but worked for me so I'm writing here just in case.

    Unity version: 2022.3.20f1
    Addressable version: 1.21.20
     
  13. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    526
    I'm having the same issue.
    Unity cannot load my addressable scenes because they are not added to the build settings.

    Everything used to work fine until a few days ago.

    Unity version: 2022.3.20f1
    Addressable version: 1.21.20

    I tried adding in what @unity_hedev recommended above, but nothing changed for me.
    Code (CSharp):
    1.  
    2. public void BeginDownload()
    3.         {
    4.             downloadHandle = Addressables.DownloadDependenciesAsync(startMenuScene);
    5.             downloadHandle.Completed += OnSceneLoaded;
    6.         }
    7.  
    8.  
    9.  
    10.         private void OnSceneLoaded(AsyncOperationHandle obj)
    11.         {
    12.             Addressables.Release(downloadHandle);// is this not the right place?
    13.              ...
    14.          }
    15.  
     
  14. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    526
    This was the only thing that helped me

     
  15. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    770
    Hey y'all, we're aware of the issue, but haven't gotten a repro project yet. If anyone here wouldn't mind filing a bug, that'd be a huge help to us.
     
  16. JakeS_97

    JakeS_97

    Joined:
    Jun 13, 2013
    Posts:
    14
    Hi, has a repro project been submitted for this issue yet? I'm running into this problem now and wouldn't mind putting together a repro over the next couple of evenings if it will help resolve the issue.
     
  17. mcbauer

    mcbauer

    Joined:
    Oct 10, 2015
    Posts:
    526
    Unity apparently updated my Addressables back to the latest somehow and this issue came back, Addressables 1.21.20.

    Rolling back once again....

    @davidla_unity sorry I am trying to get my game released and haven't had time to create a repro. Honestly, I don't want to spend time creating a simple example hoping to repro, and then it not repro because there is something more going on with the complexities of my full game. Otherwise, I totally would try to repro this because it is a VERY frustrating, especially now since Addressables updated on me and I spent the last 2 weeks chasing my tail trying to figure out why my levels stopped loading.

    Rolling back to 1.19.19 has my game working once more.