Search Unity

Feedback [0.7.5] Need to way to check a valid label exists in the build

Discussion in 'Addressables' started by bitinn, May 6, 2019.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    AFAIK, both:

    - var result = Addressables.LoadAsset<IResourceLocation>(label)
    - var result = Addressables.LoadResourceLocations(label)

    Triggers an exception when you run it on a label that's valid but not used by any items in the build. (eg. label.RuntimeKeyIsValid() would be true here)

    The difference is latter somehow still works and allow me await result.Task to see if result.Status is ok. While the former just stops Addressable loading altogether.

    I am not sure if I encountered a bug with Addressables.LoadResourceLocations, or misused it for label, either way, seems like we need a proper way to check label in exists in build in addition to key.

    (Personally I don't mind getting an actual Exception, for example from calling
    Addressables.LoadAssets<T>(label) with a valid label not in the build, it's not nice but still workable.)

    (The problem comes when we triggers an Exception but Addressable doesn't throw it to us, and instead just LogException. This means we can't try/catch to recover from it.)
     
    Last edited: May 6, 2019
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    It does seem counter intuitive that LoadResourceLocations would throw an exception with a bad key. Maybe it shouldn't. Or maybe it should, but we should also provide an interface like IsValidKey or some such. we'll ponder adn get something more useful up there.