Search Unity

How do I change Line Spacing on a custom font via script?

Discussion in 'Scripting' started by faultymoose, Jan 2, 2014.

  1. faultymoose

    faultymoose

    Joined:
    Oct 1, 2010
    Posts:
    246
    I am writing a script to handle some bitmap font generation, and I am trying to access the Line Spacing property of a custom font asset from a script, but it doesn't seem to be exposed. I've tried using reflection to get all public/non-public properties and fields but the Line Spacing doesn't show up anywhere. Is there any way to access this without having to manually set it in the inspector?
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. faultymoose

    faultymoose

    Joined:
    Oct 1, 2010
    Posts:
    246
    Excellent, thanks heaps for the tip!

    I found the property using:

    SerializedObject so = new SerializedObject(customFont);
    Debug.Log(so.FindProperty("m_LineSpacing").floatValue);
    // 0.1

    But attempting to assign anything to the value doesn't work:

    so.FindProperty("m_LineSpacing").floatValue = 99f;
    // m_LineSpacing is still equal to the default value of 0.1

    Any ideas?
     
  4. faultymoose

    faultymoose

    Joined:
    Oct 1, 2010
    Posts:
    246
    Figured it out. Have to call ApplyModifiedProperties on the serialized object after setting the floatValue field.
     
    simonpasi_XR likes this.