Search Unity

How to check if an addressables path exists?

Discussion in 'Addressables' started by MikeHergaarden, Jan 5, 2019.

  1. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    974
    When I use
    var l = Addressables.LoadAsset<GameObject>("MyAsset/NotExisting");
    for a non existing path, the editor throws ugly errors:

    InvalidKeyException encounterd in operation UnityEngine.ResourceManagement.CompletedOperation`1[UnityEngine.GameObject], result='', status='None', valid=True, location=..
    UnityEngine.AddressableAssets.Addressables:LoadAsset(Object)


    How could I check if a addressable stringpath exists? Ideally I'd want to have an
    HasAsset(string)
    method
     
    kraihd likes this.
  2. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    19
    Not sure if something new being added, or am I did this wrong in a first place, but here the way of finding all keys existing I've used while ago
    Code (CSharp):
    1. Addressables.ResourceLocators.OfType<ResourceLocationMap>()
    2. .SelectMany(locationMap =>
    3.     locationMap.Locations.Keys.Select(key => key.ToString())
    4. )
     
    AAK_Lebanon and MNNoxMortem like this.
  3. unity_YgLwdbTFIaq_CQ

    unity_YgLwdbTFIaq_CQ

    Joined:
    Nov 26, 2018
    Posts:
    7
    could you use try/catch?
     
  4. chanon81

    chanon81

    Joined:
    Oct 6, 2015
    Posts:
    76