How to import and use custom fonts in Unity

How to import and use fonts in your Text UI elements in Unity

When working with user interfaces in Unity, it’s often necessary to use a custom font for your text to improve the overall aesthetic of your game. In this article, we’ll take a step-by-step journey through the process of using a custom font for both legacy and TextMeshPro text in Unity.

  1. Where to download fonts
    1. Online font libraries
    2. Finding specific fonts
  2. Import downloaded fonts
  3. Using fonts for legacy text
  4. Using fonts for TextMeshPro text
  5. Conclusion

1. Where to download fonts

There are numerous font library websites available offering both free and paid options. When it comes to downloading a font, there is no specific website you must visit. If you know the name of the font, you can search for it on Google.

a. Online font libraries

Otherwise, you can start by exploring these two excellent options, both of which offer free fonts:

  1. Google Fonts: An expansive and cost-free font library for multiple languages, Google Fonts is one of the most popular websites for font exploration. Many fonts are open source, making them accessible for personal and commercial use, and it continually expands its library with updates.
  2. DaFont: Providing a wide range of fonts (including decorative and handwritten styles) and catering to diverse design needs, DaFont offers designers a valuable resource for unique and customisable typography. On Dafont, you can filter the fonts based on themes like fancy, script, foreign look, and more, which can be helpful.

Note that when you download a font, it’s essential to check whether it’s intended for personal use only or available for both personal and commercial use to avoid potential licensing issues.

b. Finding specific fonts

If you have a specific font you want, you can also visit sites like WhatTheFont and Identify Fonts, which are able to take screenshots of the font and tell you what the name of the font is.

You can also try googling terms like “vampire survivors font” or “subnautica font”, and you will often find Reddit threads of people who have asked similar questions — and found the answers they were looking for.


Article continues after the advertisement:


2. Import downloaded fonts

When you download a font, most of the time you will be getting a ZIP, which you will need to unzip into a folder. Once done, you will see multiple files — all of the same font, but in different formats. You only need to import ONE of these into your Unity project by simply dragging the files into your project.

Downloaded fonts
What you should see in your unzipped folder.

Note that Unity only accepts the TrueType Font (TTF) and OpenType Font (OTF) file formats, as of the time of writing this article so you just need to import either of them.

3. Using fonts for legacy text

Legacy text refers to the older text system within Unity, which remains in use in certain older projects. For newer projects, using TextMeshPro text is the preferred choice as it is a more advanced text rendering system with additional features. If you would like to learn more about the difference between legacy text and TextMeshPro text, check out this article we posted earlier this year.

To use a custom font for legacy text, you can simply drag and drop your imported TTF/OTF file into the font property under the Text component, as shown below. Once you’ve done this, the font of the text should be changing immediately.

Legacy Text component.
Legacy Text component.

If you want to set the font of legacy text through scripts, you will need to add using UnityEngine.UI namespace in order to access Text class. Then, save a reference to your Text component and set the font of it through Text.font property.

Setting the legacy text font through a script.
Setting the legacy text font through a script.

If you like to see the entire process visually, you can also watch the video below:

4. Using fonts for TextMeshPro text

Unlike legacy text, TTF/OTF files will not be recognised by TextMeshPro. You have to convert it into a TMP_FontAsset, a format TextMeshPro recognises before applying the font to your TextMeshPro text. To do so, go to Window > TextMeshPro > Font Asset Creator

Window > TextMeshPro > Font Asset Creator
Window > TextMeshPro > Font Asset Creator

Article continues after the advertisement:


From there, select the font you would like to create a TMP_FontAsset for and drag it to the Source Font File field, click on Generate Font Atlas, then scroll down and click on Save As to save the generated font asset.

How to create a TMP_FontAsset
Remember to save the generated asset somewhere inside your project folder.

Once done, you should be getting a TMP_Font Asset, which you will need to drag to the Font Asset property under TextMeshPro – Text component.

TextMeshPro - Text component
TextMeshPro – Text component

To set the font of TextMeshPro text through scripts, it is pretty much the same as legacy text, except that the namespace and class names are different as shown below.

  1. using TMPro instead of using UnityEngine.UI.
  2. TextMeshProUGUI instead of Text.
  3. TMP_FontAsset instead of Font.
Setting the TextMeshPro text font through a script.
Setting the TextMeshPro text font through a script.

If you want to see the process outlined visually, you can watch the video below.

5. Conclusion

Hope this short article helped you to have a clearer idea of how to use a custom font for text in Unity. While it may seem straightforward, it’s an aspect that new game developers can sometimes overlook. If you have any suggestions or things you would like us to add to the article, feel free to leave a comment below!


Article continues after the advertisement:


Leave a Reply

Your email address will not be published. Required fields are marked *

Note: You can use Markdown to format your comments.

For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

I agree to these terms.

This site uses Akismet to reduce spam. Learn how your comment data is processed.