Search Unity

TextMesh Pro Changing StyleSheet does not work

Discussion in 'UGUI & TextMesh Pro' started by HaynophGuard, Aug 6, 2018.

  1. HaynophGuard

    HaynophGuard

    Joined:
    Aug 29, 2017
    Posts:
    10
    I have a default StyleSheet and a new StyleSheet with one style in it named "Test". The new StyleSheet is selected in TMP Settings.asset.

    No matter what I do, <style="Test">Text</style> does not work. It just displays "<style="Test">Text". If I attempt to use a style from the default StyleShset it works fine.

    If I change the default font in the TMP Settings just to test if it's being applied, it works fine.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you changing the style sheet referenced in the TMP Settings at runtime via code or are you changing / assigning it in the Editor where it doesn't appear to take / use the new style sheet?
     
  3. HaynophGuard

    HaynophGuard

    Joined:
    Aug 29, 2017
    Posts:
    10
    I'm using it via Editor Inspector.

    https://i.imgur.com/6qs9f9G.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
  5. HaynophGuard

    HaynophGuard

    Joined:
    Aug 29, 2017
    Posts:
    10
    It's been ignored for a few days. Could you at least tell me if you have looked at them? I paid for this product and now the premium support is gone because your forum now suggests to come here for support.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am not ignoring the posts just been crazy busy and unable to get to this.

    I'll take a look later this afternoon and provide feedback thereafter.

    Update
    I have been able to reproduce the behavior and implement a solution for it.

    The following new function needs to be added to the TMP_StyleSheet.cs just before the RefreshStyles() function around line 95.

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Function to update the internal reference to a newly assigned style sheet in the TMP Settings.
    4. /// </summary>
    5. public static void UpdateStyleSheet()
    6. {
    7.     // Reset instance
    8.     s_Instance = null;
    9.  
    10.     RefreshStyles();
    11. }
    12.  
    Then in the TMP_SettingsEditor.cs, make the following changes around line 223.

    Code (csharp):
    1.  
    2. GUILayout.Space(5f);
    3. EditorGUI.BeginChangeCheck(); // Add this new line.
    4. EditorGUILayout.PropertyField(prop_StyleSheet);
    5. // Add these new lines as well.
    6. if (EditorGUI.EndChangeCheck())
    7. {
    8.      serializedObject.ApplyModifiedProperties();
    9.      TMP_StyleSheet.UpdateStyleSheet();
    10. }
    11. EditorGUILayout.EndVertical(); // existing line of code.
    12.  
    This change should make it where changing the style sheet in the TMP Settings will automatically update on text objects.

    If you are changing style from scripting after having modified to properties of the TMP Settings to allow you to do this, call this new TMP_StyleSheet.UpdateStyleSheet(); after you make you new assignment.

    These changes will be included in the next release of the TMP UPM package (not in version 1.3.0) which mostly includes UI refactoring. So the one after that ;)
     
    Last edited: Aug 9, 2018