Search Unity

Question Replacing sprite assets.

Discussion in 'UGUI & TextMesh Pro' started by pineapuru, Dec 9, 2020.

  1. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    Hey there, I've always been curious about the usage of sprites on TMPro, theres a ton of games that uses sprites for numbers or letters, which in my opinion does look very good on pixelated games or exagerated stylized games; My game is all made with pixel art and I made some pixelated numbers with some outline myself, I liked it so much that I even thought on making the letters too, the problem is, I've read bitmap fonts can't be used with text mesh pro, my solution for that was using sprite assets to use the numbers, so on code I would always make the text be <sprite=(number)>, but I don't really like this method as I can't test or experiment with the fonts with practicity, as it is also a pain to configure them.

    Is there any good way to use sprites as fonts? Like, is there any way to convert bitmap to ttf maybe? Any good hint I would really appreciate. <3
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Unity's supports bitmap fonts via the "Custom Font" option. You create a custom font, add a material that has a reference to your bitmap and then you tell the font which character is where on the texture.

    https://docs.unity3d.com/Manual/class-Font.html
     
    pineapuru likes this.
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    You can create and use Bitmap Font Assets with TMP. Instead of using the SDF modes like SDFAA, you would instead create a font asset using one of the bitmap modes like Smooth for instance.

    For bitmap text to render correctly, just make sure your render the text at 1:1 where the displayed point size is the same as sampling point size. Scaling is possible and there are several tutorials related to pixel art using TMP and process for creating bitmap font assets.
     
    pineapuru likes this.
  4. pineapuru

    pineapuru

    Joined:
    Mar 21, 2018
    Posts:
    46
    I'm sorry for such a late reply, got busy at the end of the year. Although you said I can create and use bitmap fonts, how can I create a font asset if the 'Source font file' slot only accept ttf fonts? Is there any other asset creator I have to use? What exact file type I can use to create bitmap fonts on tmpro? Thanks for your reply <3
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Take a look at the following video which covers the font asset creation process using the Font Asset Creator. The video is a bit old and mostly focuses on SDF but it still explains the bitmap modes.

    Font Assets can also be created by selecting the font file (.ttf, .ttc or .otf) and using the context menu "Create - TextMeshPro - Font Asset" and then changing the Atlas Render Mode to one of the bitmap modes as seen below.

    upload_2021-1-4_23-17-0.png

    Note, that you will need to change the shader assigned to this font asset to use the TMP Bitmap shader.
     
    pineapuru likes this.