Search Unity

Feedback Better null check for AssetLabelReference

Discussion in 'Addressables' started by bitinn, Apr 17, 2019.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Currently, if you serialize AssetLabelReference as field inspector, and forgot to set it to an actual label, the only valid way to check null appears to be
    label.labelString == ""
    , using
    label.labelString == null
    or
    label == null
    doesn't stop empty label field.
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    two notes:
    1. in the upcoming release, we do add a `RuntimeKeyIsValid` method to both `AssetLabelReference` and `AssetReference`, which should solve your problem.
    2. in general, if working with strings, I'd always recommend using `string.IsNullOrEmpty` for validation. Won't need that here, just a general note.
     
    bitinn likes this.