Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How do I create custom fonts (digits only)?

Discussion in 'UI Toolkit' started by AtomicLugia, Mar 26, 2021.

  1. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    This also might sound kinda noobish but here it goes; I want to create a font for my game using a font made of sprites. I already created the sprites here. There are digital number fonts in the internet but they may align to my custom HUD poorly. There's a way to create custom fonts in Unity by "Create -> Custom Font". But setting this up is kinda like rocket science for me. I got the "2D Texture" and material already set up but the result is kinda stinky. I would like to show the settings of the custom font but I deleted it by frustration. I know there's TextMeshPro but it seems that I can't create sprite fonts with it (or I'm doing something wrong).

    The characters are limited to 1, 2, 3, 4, 5, 6, 7, 8, 9, - and A.

    Here's the sheet:


    And here's a part of the HUD that should contain these digits:


    Any help would be appreciated!
     
  2. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    998
    Two things you can consider:

    - Make a sprite atlas, which you can assign to TextMesh Pro. Once you do that, you can insert sprites in the text with a syntax like <sprite index="0">.
    https://learn.unity.com/tutorial/textmesh-pro-sprite-assets

    - Make your own "DigitsDisplay" VisualElement which, given a number, will create the appropriate count of child elements, each displaying a single digit (you can assign sprites to a VisualElement background).

    Hope this helps!
     
  3. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    I got it working. Now, since I'm using Bolt, I have to make it so that the "Health" value, which is "100" is replaced by "<sprite index="1"><sprite index="0"><sprite index="0">". If I get this working then the problem is solved!
     
  4. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    Is there still a way to create a "legacy" custom font? TextMesh Pro is too clunky to use for displaying a value in sprite digits. Also, I'm still not experienced with C# scripting yet, sorry!
     
  5. mcoted3d

    mcoted3d

    Unity Technologies

    Joined:
    Feb 3, 2016
    Posts:
    998
    Just to make sure, are you using Bolt with UI Toolkit or with a UI Canvas? I think using Bolt with UI Toolkit might be challenging since UI Toolkit's VisualElements aren't ScriptableObjects.

    I'm not sure. I think TextMesh Pro is our only text system that supports sprite atlas. Font files are usually vector shapes, not sprites.
     
  6. AtomicLugia

    AtomicLugia

    Joined:
    Aug 15, 2020
    Posts:
    54
    For now, I got it working. Was difficult to set up in Bolt but it worked! There's a way to make Bolt compatible with TextMesh Pro.