Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

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:
    972
    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:
    7
    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:
    47