Search Unity

[Feature Request] API Able to mark assets in Resources folder as addressable by C# script

Discussion in 'Addressables' started by jacky-kschou, Oct 28, 2020.

  1. jacky-kschou

    jacky-kschou

    Joined:
    May 4, 2013
    Posts:
    73
    I manage to get it working by making AddressableAssets.MoveAssetsFromResources a public function.

    I wish I had a safer way to do that.

    My example code:

    Code (CSharp):
    1. var settings = AddressableAssetSettingsDefaultObject.Settings;
    2. var group = AddressableAssetSettingsDefaultObject.Settings.FindGroup(groupName);
    3. if (!group)
    4. {
    5.     throw new Exception($"Addressable : can't find group {groupName}");
    6. }
    7. var entry = AddressableAssetSettingsDefaultObject.Settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(path), group,
    8.     false,
    9.     true);
    10.  
    11. if (path.Contains("Resources/"))
    12. {
    13.     var newName = path.Replace("\\", "/");
    14.     newName = newName.Replace("Resources", "Resources_moved");
    15.     newName = newName.Replace("resources", "resources_moved");
    16.  
    17.     settings.MoveAssetsFromResources(
    18.         new Dictionary<string, string>() {{AssetDatabase.AssetPathToGUID(path), newName}}, entry.parentGroup);
    19. }
    20.  
    21. if (entry == null)
    22. {
    23.     throw new Exception($"Addressable : can't add {path} to group {groupName}");
    24. }
    25. entry.labels.Add(groupName);
    26. settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    I'll forward your suggestion to the team for review!
     
  3. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    763
    Hey, good suggestion. I don't know if or when we'd get to something like this but I did want to throw out a suggestion. If you wanted to you could rename your Resources folder to Resources_moved or whatever you like and then drag that entire folder into an Addressable group, marking the entire thing (and all the assets inside it) as Addressable. Though, that might not be exactly what you're looking for.