Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Please support loading Addressables into Editor

Discussion in 'Addressables' started by chrisk, Jan 8, 2020.

  1. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hey Unity,
    For some sad reasons, I separated my project into several projects.
    One project contains only static maps and it generates addressables. And the main project needs to load the static maps so that it can add dynamic elements on top of it, however, I found out that it cannot be loaded into the Editor. It makes me even sadder.
    I can explain more about the sad reasons if you want to know but can you please support the edit time loading?

    Thanks
     
  2. zhuxianzhi

    zhuxianzhi

    Joined:
    Mar 30, 2015
    Posts:
    122
    Addressables does not support synchronous loading. Use AssetDatabase.LoadAssetAtPath under the editor.
    You can find the path of the resource by "address";

    Code (CSharp):
    1. public static string GetAssetPath(string address)
    2.     {
    3.         var aaSettings = AddressableAssetSettingsDefaultObject.Settings;
    4.         if (aaSettings == null)
    5.             throw new ArgumentException(nameof(aaSettings));
    6.  
    7.         var entries = from addressableAssetGroup in aaSettings.groups
    8.             from entrie in addressableAssetGroup.entries
    9.             select entrie;
    10.  
    11.         foreach (var entry in entries)
    12.         {
    13.             var allEntries = new List<AddressableAssetEntry>();
    14.             entry.GatherAllAssets(allEntries, true, true, false);
    15.             for (int i = 0; i < allEntries.Count; i++)
    16.             {
    17.                 var assetEntry = allEntries[i];
    18.  
    19.                 if (assetEntry.address == address)
    20.                 {
    21.                     return assetEntry.AssetPath;
    22.                 }
    23.             }
    24.         }
    25.  
    26.         throw new ArgumentException("error key:" + address);
    27.     }
     
  3. chrisk

    chrisk

    Joined:
    Jan 23, 2009
    Posts:
    704
    Hi, thanks for the reply.
    Are you sure this will load the addressable into the Scene Hierarchy during edit time?