Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[ProGrids] EditorUtility.GetColorFromJson

Discussion in 'World Building' started by esc_marcin, Sep 5, 2019.

  1. esc_marcin


    Sep 30, 2016
    When ProGrids loads its preferences it tries to parse colors using this function, but if you haven't customized anything the colors are empty strings. This is annoying when debugging because it breaks on the throw inside JsonUtility.FromJson several times every play iteration. It also seems passing an empty string here isn't exceptional but by design. Can you add an early out to avoid this exception for a more pleasant debugging experience?

    i.e. change it to

    Code (CSharp):
    1. internal static Color GetColorFromJson(string json, Color fallback)
    2. {
    3.     if ( String.IsNullOrEmpty( json ) )
    4.         return fallback;
    6.     try
    7.     {
    8.         return JsonUtility.FromJson<Color>(json);
    9.     }
    10.     catch
    11.     {
    12.         return fallback;
    13.     }
    14. }