Search Unity

TextMesh Pro Material tag only working with one font

Discussion in 'UGUI & TextMesh Pro' started by hzandri, Dec 23, 2018.

  1. hzandri

    hzandri

    Joined:
    Sep 8, 2017
    Posts:
    6
    For some reason only one of my fonts will respond to the <material> tag while all the other fonts are not affected by this tag and the tag simply appears as regularly drawn text. They are all in the same folder, so I do not see what the problem is.
    Any help would be appreciated. Thanks!
     
  2. hzandri

    hzandri

    Joined:
    Sep 8, 2017
    Posts:
    6
    Looks like each font needs its own material preset to be created for each variant.
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Correct. The <material> tag switches to the material which has a reference to some atlas texture. Now if the atlas texture referenced by the material is the same as the font asset then everything will be cool. However, if the material references a different atlas texture then the text will appear broken.

    There are certainly things I could do behind the scene to ensure that no matter what material is set that I match the appropriate atlas texture. With material property blocks this could be done easily however, material property blocks do not work with the CanvasRenderer which would result in said functionality being available for the normal <TextMeshPro> component that works with the Mesh Renderer but not available for the Canvas system.

    When I have time, I can certainly revisit this :)
     
  4. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    Hi Stephan, we just started using MaterialPresets, we would love to avoid having to duplicate and maintain all the material presets for each font.

    What would you say is the best practice for sharing material presets between fonts?

    Right now we are thinking about having an editor script that maintains all the duplicates in sync and we only adjust the reference ones. Then on awake depending on the user language choice, we will set the font and proper material as the sharedMaterial in the TextMeshProUGUI instance.

    Thanks for any information and happy new year.

    Rubén
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Material Presets are very efficient and lightweight and reference the atlas texture of the original font asset and as such avoid duplication of resources.

    In terms of trying to have a single material preset that is re-used with multiple font assets, there are two key issues.

    The first being that fonts come in all shapes and size with different metrics and as such the material properties of that look good on one font may not look equally good on another. Having separate Material Presets per font assets allows you to specifically tune the material properties to achieve the exact visual appearance you desire.

    Second, in order to have multiple text objects using different font assets, you will need to be creating material instances and manage those which isn't any easier than managing the Material Preset themselves. In addition, you will need to make sure the correct Atlas Texture is assign to these instanced material as well as correct padding value, texture size, etc. Ie. lots of stuff to managed behind the scene.

    On the other hand, assuming the characters / fonts look very similar in terms of size / shape and that you use the same sampling point size to padding ratio between these, you could create an instance material to which you copy the relevant material properties from their source default material (this is what the fallback system does behind the scene).
     
  6. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    16
    Hello Stephan.
    I tried to use material tag in my project, but only "default" material affects in my case and any other specified material preset (tried even currently using material preset too) are ignored and appeared as regular text. Again, I have some font and many material presets for them.
    What am I doing wrong, could you help, please? Thanks in advance.

    P.S. I am trying to use material setting with using <sprite name> tag. Not sure it will work, but currently I have no idea how manually replace material in automatically created submesh.
     
  7. t1ny_bear

    t1ny_bear

    Joined:
    Oct 2, 2020
    Posts:
    16
    It was my bad, when I moved my material into Fonts&Materials folder in TextMesh Pro folder it correctly found now.
    So, as I can see, combination of <material> and <sprite name> doesn't work. It seems I should find another way to replace default sprite material to intended one.
     
    Last edited: Feb 8, 2021