Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question <Font> Tag not working when added to text during runtime

Discussion in 'UGUI & TextMesh Pro' started by dr4, Apr 1, 2023.

  1. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    108
    I have a TextMeshProGui font that are icons, I added it to the "Fonts & Materials" folder and got it to work when needed with the "font" tag, this font helps me to put the right icon when needed in the text, which is dynamic, so something like "\u243A" when the font is applied will become an icon, but it does not work in all scenarios.

    if I have something like:

    Code (CSharp):
    1. Press <color=#FF8424>'This will be replaced'</color>
    and during runtime in a script I replace the text to have a specific font:

    Code (CSharp):
    1. Press <color=#FF8424> <font="MyFont">\u243A</font></color>
    the font is not applied and the output has no icons, just the plain text:

    Code (CSharp):
    1. Press <color=#FF8424>\u243A</color>
    But I noticed that any change to that textmesh pro in the inspector, will trigger the font change, so if I add any text or change the font size "\u243A" magically becomes an icon.

    I tried to apply some updates after the replace, even change the font size to see if that would trigger the new font, but no success:


    Code (CSharp):
    1.     textMeshPro.richText = true;
    2.             textMeshPro.ForceMeshUpdate();
    3.             textMeshPro.UpdateFontAsset();
    4.              textMeshPro.SetAllDirty();
    5.  
    I also tried to use the "OnFontAssetRequest" which is triggered correctly but returning the font does not change the outcome

    How can I replace a text in a script with the "<font>" tag and expect it to apply the font?
     
    Last edited: Apr 2, 2023
  2. dr4

    dr4

    Joined:
    Jan 14, 2015
    Posts:
    108
    I saw that the issue is with the unicode not the font tag, text mesh doesn't seem to recognise unicodes added at runtime