Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[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. }