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.

TextMesh Pro Font Weights (typefaces) and how to use them

Discussion in 'UGUI & TextMesh Pro' started by Cleverlie, Jun 22, 2019.

  1. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    216
    Hi, I was wondering if there is an easy way to use the different font weights that you can assign to the font asset, I mean, if I have Roboto-light, Roboto-bold, Roboto-medium etc, then I can assign them in the "Font Weights" section of my "Regular" version, then when I activate the Bold option on the text object it will use the Bold font instead of the regular one. the same goes if I use the rich text "<b>" tags.

    I wonder how can I do the same but for the other weights, other than bold, such as Light, Medium, Heavy, etc.

    cheers!
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    Support for all font weights is available in the latest releases of TMP. That would be version 1.4.x for Unity 2018.3 or newer and 2.0.x for Unity 2019.x.

    upload_2019-6-23_9-9-27.png

    In these latest releases, you would create font assets using these correct font weight typeface and assign it to the appropriate font weight in the font asset inspector.
     
    Midiphony-panda likes this.
  3. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    216
    Hi Stephan, yes this is what I've been doing, what I'm asking is actually how to use them, I mean you know how you can use the "<b>" tags or the "B" button in the TMPUGUI object inspector to set all or a part of your text to bold weight, how can we do the same to set it to light, heavy, medium etc.

    is there such thing like a <medium-weight> tag or a button to change the weight? thanks for the help!
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    There is indeed. The tag is <font=weight=xxx>. Here is another example

    "A<font-weight=500>B</font-weight>C"

    upload_2019-6-24_9-26-49.png

    upload_2019-6-24_9-28-12.png
     
  5. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    216
    oh amazing! that's exactly what I've been looking for! I also realized that the text object has a fontWeight property that I guess it can override the rich text tags and set the overall weight too.

    thanks again, I really love TMP and how you thought about every aspect, the UX is near perfection, is one of that assets so good that you wish Unity integrates it out of the box.. oh wait! they already did it!

    cheers.
     
  6. AM-Dev

    AM-Dev

    Joined:
    Aug 5, 2015
    Posts:
    31
    Hi there,
    I still don`t get how to use the font weights. I`ve got a .ttc font which in windows shows me that different font weights are available. So I could install them all, like: "Book", "Black", "Heavy", "Light", etc.

    How do I get these assigned to the font weights in the picture and how do I use them in a text field?
    Thanks

    Update:
    I read about ttc and how to get the ttf files for windows here: https://superuser.com/questions/114...-on-windows-error-ttc-does-not-appear-to-be-a
    And here`s more info about how to setup the font weights: https://forum.unity.com/threads/sep...weights-how-to-correctly-combine-them.840070/
    Implementing it now.
     
    Last edited: Mar 15, 2020
  7. YVovchuk

    YVovchuk

    Joined:
    Apr 9, 2021
    Posts:
    1
    Hello, guys. Can I somehow generate 1 font asset for 3 weights of the same font? I need to use Thin, Regular and Bold weights, but I don't want to generate 3 different assets, because build size will increase and we want to keep it as small as possible.
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    Font styles / weights are usually contained in separate font files where assuming you are using Dynamic Font Assets, you will need to include each of those font files or in the case where these font styles and weights are contained on a .ttc file include the .ttc file. If you are using Dynamic OS font assets (introduced in the latest preview release) then you will need to include those font files in the Editor to create the font asset but unlike Dynamic Font Assets, they will not be included in the build where instead TMP will search for them on the target platform.

    If you are using static font assets, then the source font files are not needed. You will still need 3 separate font assets but whether all 3 were combined into 1 vs 3 the size would be roughly the same.
     
    YVovchuk likes this.
  9. heromade

    heromade

    Joined:
    Aug 27, 2017
    Posts:
    33
    For of all, thank you for this. It helped me! But you should edit this: <font=weight=xxx> to the correct <font-weight=xxx>. The equality sign is wrong. I just copied that bit with the equality sign and changed the xxx to 700 and was wondering for 10 minutes why it was not working.
     
  10. Mahunreah

    Mahunreah

    Joined:
    Mar 1, 2018
    Posts:
    10
    Dredika and Vivien_Lynn like this.