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

How to get all addressables in a folder?

Discussion in 'Addressables' started by Diorgo24BitGames, Feb 25, 2020.

  1. Diorgo24BitGames

    Diorgo24BitGames

    Joined:
    Sep 13, 2018
    Posts:
    5
    Hi

    I'd like to create an editor script that does the following:
    - Loop through all the prefabs in a folder.
    - Determine which of the prefabs are marked as addressable, and add them to a list of AssetReferences (or address strings). (The list is serialized on a ScriptableObject.)


    1) How do I determine if a prefab is marked as addressable?

    2) And how do I get the AssetReference (or address string)?



    Additional info:

    I currently have a workaround that uses SetEditorAsset, but it's not ideal.

    Example of the workaround:

    EDITOR SCRIPT:
    Code (CSharp):
    1. var assetReference = new AssetReference();
    2. if (assetReference.SetEditorAsset(prefab))
    3. {
    4.     list.Add(assetReference);
    5. }
    The problem with the above code is that it adds all the prefabs to the list, whether they are marked as addressable or not.


    RUN-TIME SCRIPT:
    Code (CSharp):
    1. foreach (var assetReference in list)
    2. {
    3.     assetReference.LoadAssetAsync<GameObject>();
    4. }

    .