Search code examples
c#unity-game-engineloadingassetsaddressables

Unity. How to load all addressables from folder


I have such addressables structure: enter image description here

  1. Is it correct to put each level in separate group ? (is group = bundles ?)
  2. How I can load list of each level config and scenes ?

Should I load them by labels or hold anywhere AssetReferences on it ?

I want to load first configs, show tumbnails of each level and then when player choose one of this load concrete scene


Solution

  • I would tag all the configs with the same label, and NOT tag the scenes. On app start load all the configs by label.

    Where key = label;

    private async void DownloadAssetsAsync(AssetLabelReference key)
    {
       var downloadHandle = Addressables.DownloadDependenciesAsync(key);
       try
       {
          while (!downloadHandle.IsDone)
          {
            await Task.Yield();
          }
       }
       catch (Exception ex)
       {
          Debug.Log("Asset error: " + ex.Message);
       }
    }
    

    Then when the user selects the level download the required level. You could also use the same method to ensure that the first few levels are downloaded and ready to play by labelling them for initial start, so at least the first few levels are downloaded and ready to use before the player selects it.