Как добавить шрифт в unity
Перейти к содержимому

Как добавить шрифт в unity

  • автор:

Font assets

To add a font to your project you need to place the font file in your Assets folder. Unity will then automatically import it. Supported Font formats are TrueType Fonts (.ttf files) and OpenType Fonts (.otf files).

To change the Size of the font, highlight it in the Project View and you have a number of options in the Import Settings in the Inspector A Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary .

Import Settings for a fontImport Settings for a font

Property: Function:
Font Size The size of the font, based on the sizes set in any word processor.
Rendering mode The font rendering mode, which tells Unity how to apply smoothing to the glyphs.
Character The character set of the font to import into the font texture
Setting this mode to Dynamic causes Unity to embed the font data itself and render font glyphs at runtime (see below).

Import Settings specific to dynamic fonts

Property: Function:
Include Font Data This setting controls the packaging of the font when used with Dynamic font property. When selected the TTF is included in the output of the build. When not selected it is assumed that the end user will have the font already installed on their machine. Note that fonts are subject to copyright and you should only include fonts that you have licensed or created for yourself.
Font Names A list of fallback fonts to use when fonts or characters are not available (see below).

After you import the font, you can expand the font in Project View to see that it has auto-generated some assets. Two assets are created during import: “font material” and “font texture”. Unlike many applications you might be familiar with, fonts in Unity are converted into textures, and the glyphs that you display are rendered using textured quads A primitive object that resembles a plane but its edges are only one unit long, it uses only 4 vertices, and the surface is oriented in the XY plane of the local coordinate space. More info
See in Glossary . Adjusting the font size effectively changes how many pixels The smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary are used for each glyph in this generated texture. Text Mesh The main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary assets are 3d geometry textured with these auto-generated font textures. You will want to vary the size of the font to make these assets look crisp.

Dynamic fonts

When you set the Characters drop-down in the Import Settings to Dynamic, Unity will not pre-generate a texture with all font characters. Instead, it will use the FreeType font rendering engine to create the texture on the fly. This has the advantage that it can save in download size and texture memory, especially when you are using a font which is commonly included in user systems, so you don’t have to include the font data, or when you need to support asian languages or large font sizes (which would make the font textures very large using normal font textures).

When Unity tries to render text with a dynamic font, but it cannot find the font (because Include Font Data was not selected, and the font is not installed on the user machine), or the font does not include the requested glyph (like when trying to render text in east Asian scripts using a latin font, or when using styled bold/italic text), then it will try each of the fonts listed in the Font Names field, to see if it can find a font matching the font name in the project (with font data included) or installed on the user machine which has the requested glyph. If none of the listed fallback fonts are present and have the requested glyph, Unity will fall back to a hard-coded global list of fallback fonts, which contains various international fonts commonly installed on the current runtime platform.

Note that some target platforms (WebGL, some consoles) do not have OS default fonts Unity can access for rendering text. For those platforms, Include Font Data will be ignored, and font data will always be included. All fonts to be used as fallbacks must be included in the project, so if you need to render international text or bold/italic versions of a font, you need to add a font file which has the required characters to the project, and set up that font in the Font Names list of other fonts which should use it as fallbacks. If the fonts are set up correctly, the fallback fonts will be listed in the Font Importer inspector, as References to other fonts in project.

Default font asset

The default font asset is a dynamic font which is set up to use Arial. If Unity can’t find the Arial font on your computer (for example, if you don’t have it installed), it will fall back to a font bundled with Unity called Liberation Sans.

Liberation Sans looks like Arial, but it does not include bold or italic font styles, and only has a basic Latin character set — so styled text or non-latin characters may fall back to other fonts or fail to render. It does however have a license which allows it to be included in player builds.

Custom fonts

To create a custom font select ‘Create->custom font’ from the project window. This will add a custom font asset to your project library.

The Ascii Start Offset field is a decimal that defines the Ascii index you would like to begin your Character Rects index from. For example, if your Ascii Start Offset is set to 0 then the capital letter A will be at index 65 but if the Ascii Start Offset is set to 65 then the letter A will be at index 0. You can consult the Ascii Table here but you should bear in mind that custom font uses the decimal ascii numbering system.

Tracking can be set to modify how close each character will be to the next character on the same line and Line spacing can be set to define how close each line will be to the next.

To create a font material you will need to import your font as a texture then apply that texture to a material, then drag your font material onto the Default Material section.

The Character Rects section is where each character of your font is defined.

The Size field is for defining how many characters are in your font.

Within each Element there is an index field for the ascii index of the character. This will be an integer that represents the character in this element.

To work out the UV values you need to figure out how your characters are positioned on a scale of 0 to 1. You divide 1 by the number of characters on a dimension. For example if you have a font and the image dimensions on it are 256×128, 4 characters across, 2 down (so 64×64), then UV width will be 0.25 and UV height will be 0.5.

For UV X and Y, it’s just a matter of deciding which character you want and multiplying the width or height value times the column/row of the letter.

Vert size is based on the pixel size of the characters e.g. your characters are each 128×128, putting 128 and –128 into the Vert Width and Height will give properly proportioned letters. Vert Y must be negative.

Advance will be the desired horizontal distance from the origin of this character to the origin of the next character in pixels. It is multiplied by Tracking when calculating the actual distance.

Example of custom font inspector with valuesExample of custom font inspector with values

Unicode support

Unity has full unicode support. Unicode text allows you to display German, French, Danish or Japanese characters that are usually not supported in an ASCII character set. You can also enter a lot of different special purpose characters like arrow signs or the option key sign, if your font supports it.

To use unicode characters, choose either Unicode or Dynamic from the Characters drop-down in the Import Settings. You can now display unicode characters with this font. If you are using a Text Mesh A Mesh component that displays a Text string More info
See in Glossary , you can enter unicode characters into the Component’s Text A non-interactive piece of text to the user. This can be used to provide captions or labels for other GUI controls or to display instructions or other text. More info
See in Glossary field in the Inspector.

You can also use unicode characters if you want to set the displayed text from scripting. The C# compiler fully supports Unicode based scripts A piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary . You have to save your scripts with UTF–16 encoding. Now you can add unicode characters to a string in your script and they will display as expected in UnityGUI or a Text Mesh.

Note that surrogate pairs are not supported.

Changing Font Color

There are different ways to change the color of your displayed font, depending on how the font is used.

Text Mesh

If you are using a Text Mesh, you can change its color by using a custom Material An asset that defines how a surface should be rendered. More info
See in Glossary for the font. In the Project View, click on Create > Material, and select and set up the newly created Material in the Inspector. Make sure you assign the texture from the font asset to the material. If you use the built-in GUI/Text Shader shader for the font material, you can choose the color in the Text Color property of the material.

Text Mesh Pro in Unity: Font Import Guide

This tutorial will cover the difference between Text Mesh Pro fonts and standard fonts in Unity. Then, this tutorial will explain how to import a font to Unity to use it with Text Mesh Pro. Finally, it will provide recommendations for where you can find custom fonts that you can add to Unity.

What is the difference between TMP Fonts and standard Unity fonts?

TMP fonts are better; use them.

Import a TMP Font

  1. Import the .ttf or .otf file to your project
  2. Select the font file
  3. Press CTRL + SHIFT + F12 to create a new font asset
  4. Open the font asset
  5. Click Update Atlas Texture
  6. Change the Character Set
  7. Click Generate Font Atlas
  8. Assign the font to a TMP component.

Where to find custom fonts

Discover the Power of Text Mesh Pro Fonts in Unity

In Unity, choosing the right fonts for your project can have a significant impact on the visual appeal and readability of your text. While Unity's default text renderer gets the job done, it may not provide the level of quality and versatility you desire. That's where Text Mesh Pro (TMP) comes in. TMP is an alternative text renderer in Unity that offers enhanced visual fidelity and advanced features for creating better text elements in your games or applications, especially compared to standard Unity fonts.

In this tutorial, we will explore the differences between Text Mesh Pro fonts and standard fonts in Unity, and explain why Text Mesh Pro is often the preferred choice. We'll walk you through the process of importing a font into Unity and using it with Text Mesh Pro so that you can use this text rendering solution.

Additionally, we'll provide recommendations on where to find custom fonts to add a unique touch to your Unity projects.

Whether you're a game developer, UI designer, or simply interested in optimizing text rendering in Unity, this tutorial will equip you with the knowledge and tools to improve the visual impact of your text elements.

Text Mesh Pro Fonts vs. Standard Fonts vs. “Unity” fonts

Most fonts are stored in one of several formats: TrueType (.ttf), OpenType (.otf), and Web Open Font Format (.woff / .woff2). Under the hood, formats like TrueType describe each character (glyph) using a series of line segments and curves — not pixels.

Unity includes a text renderer by default (i.e., “Unity Fonts”), but it doesn’t look good and offers limited features. Unity’s default text renderer is directly compatible with TrueType and OpenType fonts. You just drag and drop the font into the text renderer. Under the hood, Unity converts the font to a texture atlas and samples that texture atlas during rendering. Unity renders the character glyphs directly to the texture atlas, so the character glyph is scaled to a particular font resolution.

Text Mesh Pro is an alternative text renderer that looks much nicer. It is sometimes abbreviated as TMP. Text Mesh Pro is not directly compatible with these common font formats. Instead, Text Mesh Pro requires you to pre-generate an SDF font atlas, which is a special texture file that Text Mesh Pro can create using a standard font format — TrueType or OpenType. In contrast to Unity’s default texture atlas, the TMP font atlas uses a distance field for each glyph. This approach enables TMP to render fonts more smoothly at varying sizes and also makes it easier to render outlines or other text effects.

In the next section, this tutorial will review how to use Text Mesh Pro to import a standard font format into Unity.

Importing Fonts to Unity using Text Mesh Pro

Overview

With Text Mesh Pro, you can use the power of Text Mesh Pro Fonts, which render as SDFs, to achieve smooth and high-quality font rendering in your Unity project.

It is fairly easy to import a font into Unity for use with Text Mesh Pro.

This section you will learn how to import a font to Unity, how to use Text Mesh Pro to create a font asset, and how to use Text Mesh Pro to generate a font atlas.

Then, we will cover how to create a Text Mesh Pro GameObject and how to apply the Text Mesh Pro font asset to that GameObject.

Install Text Mesh Pro

Text Mesh Pro is included with Unity — you do not need to install anything or import any packages. If you previously removed Text Mesh Pro from your project, you can import it from the Package Manager.

Setup

If you already have a font asset (a .ttf or .otf file) in your project, skip this step.

If you don’t have a font asset in your project, you need to download one. To follow along, download Roboto from Google Fonts now. Go to the Roboto page on Google Fonts: https://fonts.google.com/share?selection.family=Roboto.

Click Download All, then extract the .zip file, and then drag and drop the Roboto-Regular.ttf file from the directory into your Unity project.

Import the .ttf file

You don’t really need to do anything with the .ttf file.

Use Text Mesh Pro to create a TMP Font Asset with the .ttf file

Once you have the font file (.ttf or .otf) imported into your Unity project, create a new Unity Font Asset with Text Mesh Pro.

To import a font into Unity for use with Text Mesh Pro, you need to create a Unity Font Asset using Text Mesh Pro. The Unity Font Asset serves as a container for your imported font, allowing you to leverage its features and apply it to Text Mesh Pro components in your project.

You can use the keyboard shortcut or the context menu to use Text Mesh Pro to create a Text Mesh Pro font asset from the .ttf file that you imported.

To use the keyboard shortcut: Click on the .ttf file, then press CTRL + SHIFT + F12.

To use the context menu: Right click on the .ttf file -> Create -> TextMeshPro -> Font Asset.

As mentioned previously, Text Mesh Pro uses a font atlas to render the glyphs to screen. When you create the Font Asset, Text Mesh Pro does not automatically create the font atlas.

So, you still need to build the font atlas within this Text Mesh Pro font asset in order to use the font with Text Mesh Pro.

Build the Font Atlas

Click on the font asset in your project. In the Inspector, click “Update Atlas Texture”.

Text Mesh Pro will open a new editor window called the Font Asset Creator.

The default settings are mostly fine for now, but you do need to change the Character Set from Unicode Range (Hex) to ASCII or Extended ASCII. The Unicode Range option expects you to provide a list of Unicodes that Text Mesh Pro should import. The ASCII and Extended ASCII options will automatically import all standard font glyphs that are included in the font file. Do that now.

Then, click “Generate Font Atlas”. Text Mesh Pro will quickly generate a font atlas for this font. Once it’s done, click Save. Your font asset is now configured and ready to use.

Create Text Mesh Pro GameObject

To use your new font asset, you need a Text Mesh Pro component in your project.

In your toolbar, GameObject -> UI -> Text — TextMeshPro.

Click on the new GameObject to view it in the Inspector.

Then, assign your Text Mesh Pro font asset to the Font Asset field in the Inspector.

Adding Custom Fonts to Unity

Overview on Finding Fonts

This section will provide you with some examples of websites where you can find fonts for your project. Keep in mind that each font may have a different license, and different websites offer different licensing terms for various fonts.

Google Fonts

Google Fonts has a reliable and large library of open or open-ish fonts. You can use many (most) of these fonts for commercial use. Make sure to check the licenses for any attribution requirements. Google Fonts also has a great set of articles and FAQs on how to choose a good font, how to use your font appropriately, and how to set up hierarchy with fonts.

The League of Movable Type

The League of Movable Type is an open-source font foundry. (A font foundry is an organization that creates new fonts). They have some good stuff. It’s open-source.

Font Squirrel

Font Squirrel is a directory of licensed-for-commercial-use fonts. Many of these fonts are also available on Google Fonts. Pick whichever UI you prefer.

Font Licensing

This is not legal advice. In general, you will want to look for fonts that are licensed under the Open Font License (OFL). These fonts are open-source, so they are free to use for personal and commercial use. You can purchase fonts, but paid fonts can be expensive, and licensing restrictions can be tricky.

System Font Rendering

I briefly covered this during the article, but I’ll reiterate it here. Unity does not use the system font renderer to draw text in the engine. For example, in Windows, most applications use DirectWrite (DWrite), a Direct2D API, to rasterize and render text. Let’s call this the native API. In contrast, Unity has its own API (Text, Text Mesh Pro) that rasterizes and renders the font.

If your font in Unity looks blurry, weird, or different than you expect compared to how it appears on the web, on your desktop, or in the font file inspector, this could be the reason why.

It is possible that Unity does not use DWrite or other system-level font rasterizers for performance reasons or for cross-compatibility and consistency reasons.

Improve Your Unity Projects with Text Mesh Pro Fonts and Unity Font Assets

In this tutorial, we have explored the differences between Text Mesh Pro fonts and standard fonts in Unity, highlighting the advantages of using Text Mesh Pro for enhanced visual quality and advanced typographical options. We've walked you through the step-by-step process of importing a font into Unity and creating a Text Mesh Pro font asset, enabling you to use this powerful text renderer.

Additionally, we have provided recommendations on where to find custom fonts, including reliable sources like Google Fonts, The League of Movable Type, and Font Squirrel. These resources offer a wide range of open or open-ish fonts, allowing you to add a personalized touch to your Unity projects.

By understanding the distinctions between Text Mesh Pro and standard fonts, and by leveraging the capabilities of Text Mesh Pro, you can improve the visual impact and readability of text elements in your games or applications.

Remember, while Unity's default text renderer serves its purpose, Text Mesh Pro provides a superior alternative with its smooth font rendering and extensive features. So don't hesitate to dive into the world of Text Mesh Pro fonts and unlock the full potential of text in your Unity creations.

Thank you for joining me on this tutorial, and I hope it has empowered you to create visually stunning text elements in your Unity projects. If you have any further questions or would like to delve deeper into game development, feel free to join our game dev Discord server.

Happy text rendering and game development!

Further Reading

A Brief Review of Font Rendering

It’s not a requirement, but it is good to understand what is happening when you render a font glyph — both on your OS and in Unity. Smashing Magazine has written a fairly solid introduction to font rendering.

More on Font Features

Text Mesh Pro offers you the option to enable Font Features. Font Features are advanced typographical options like small caps, ligatures, and tabular (mono-spaced) numerals.

Unity Font Assets Documentation

Unity has good documentation on their manual that covers how to import and use font assets for the default text renderer. I recommend that you never use the default text renderer.

Text Mesh Pro Documentation

Unity has good documentation on their Text Mesh Pro package that covers a whole lot more than what I addressed in this article. If you are going to use Text Mesh Pro (and you should use Text Mesh Pro), then bookmark the documentation and spend some time reading through it.

More on Font Licensing

Overview on Font Licensing

Font licensing is an essential aspect to consider when using fonts in your projects, whether they are for personal or commercial use. Fonts, like any other creative work, are protected by copyright law, which grants exclusive rights to the creator or copyright holder. Understanding font licensing helps ensure that you use fonts legally and respect the rights of font designers and creators.

When selecting fonts for your Unity projects, it's important to consider the following aspects.

License Types

Fonts are often distributed under various license types, each with specific terms and conditions. The most common font license types include open-source licenses like the Open Font License (OFL), commercial licenses, and freeware licenses. It's crucial to review the license terms associated with the fonts you use to determine if they align with your intended usage.

Usage Restrictions

Font licenses may have specific restrictions on usage, such as limitations on the number of installations, geographical restrictions, or restrictions on commercial use. Make sure to carefully review the license terms to ensure your usage complies with the font's license restrictions.

Attribution Requirements

Some fonts require attribution to the font designer or copyright holder as a condition of use. This means you need to credit the font creator in your project, typically by including their name or a designated attribution statement. Be sure to check if the font you want to use has any attribution requirements and fulfill them accordingly.

Redistribution and Modification

Fonts may have restrictions on redistribution or modification. Some fonts may allow redistribution, enabling you to share the font files with others, while others may restrict redistribution entirely. Similarly, modification rights vary depending on the font's license. It's crucial to respect these restrictions and only redistribute or modify fonts within the boundaries of the license terms.

Commercial Use

If you intend to use fonts for commercial purposes, ensure that the font's license permits such usage. Some fonts are specifically licensed for non-commercial or personal projects only. Verifying the font's license compatibility with your commercial use is crucial to avoid legal complications down the line.

Conclusion

By being mindful of font licensing and adhering to the terms and conditions set by font creators, you can ensure that you use fonts legally and respect the rights of the font design community. When in doubt, review the license information provided with the font or contact the font designer or copyright holder directly for clarification.

Remember, font licensing is important to protect the intellectual property rights of font creators and promote fair usage of their work. So, as you explore and integrate fonts into your Unity projects, be sure to pay attention to font licenses and use them in accordance with the applicable terms and conditions.

Please note that this explanation provides general guidance and is not legal advice. For specific legal concerns regarding font licensing, you should always consult a legal professional or refer to the specific license agreements associated with the fonts you intend to use.

Michael Sacco
Founder & CEO

Michael Sacco is the Founder and CEO of OccaSoftware where he specializes in developing game assets for Unity game developers. With a background ranging from startups to American Express, he's been building great products for more than 10 years.

Как добавить шрифт в TextMeshPro в Unity?

Перетаскиваете ваш шрифт в Unity. Затем Window — Text Mesh Pro — Font Asset Creator. В верхнем поле выбираете шрифт и жмёте Generate Font Atlas и выбираете папку куда сохранить ассет. Если нужно с кириллицей, то в поле Character Set выбираем Unicode Range (Hex) и в поле ниже прописываем 0400-04ff, если нужно ещё с английскими буквами, символами и цифрами, то 0000-04ff

Дизайн сайта / логотип © 2023 Stack Exchange Inc; пользовательские материалы лицензированы в соответствии с CC BY-SA . rev 2023.8.29.43607

Нажимая «Принять все файлы cookie» вы соглашаетесь, что Stack Exchange может хранить файлы cookie на вашем устройстве и раскрывать информацию в соответствии с нашей Политикой в отношении файлов cookie.

Text Mesh Pro in Unity: Font Import Guide

OccaSoftware - Game Assets for Unity

This article on Text Mesh Pro is reposted from OccaSoftware.

What you will learn

This tutorial will cover the difference between Text Mesh Pro fonts and standard fonts in Unity. Then, this tutorial will explain how to import a font to Unity to use it with Text Mesh Pro. Finally, it will provide recommendations for where you can find custom fonts that you can add to Unity.

What is the difference between TMP Fonts and standard Unity fonts?

TMP fonts are better; use them.

Import a TMP Font

  1. Import the .ttf or .otf file to your project
  2. Select the font file
  3. Press CTRL + SHIFT + F12 to create a new font asset
  4. Open the font asset
  5. Click Update Atlas Texture
  6. Change the Character Set
  7. Click Generate Font Atlas
  8. Assign the font to a TMP component.

Where to find custom fonts

Discover the Power of Text Mesh Pro Fonts in Unity

In Unity, choosing the right fonts for your project can have a significant impact on the visual appeal and readability of your text. While Unity’s default text renderer gets the job done, it may not provide the level of quality and versatility you desire. That’s where Text Mesh Pro (TMP) comes in. TMP is an alternative text renderer in Unity that offers enhanced visual fidelity and advanced features for creating better text elements in your games or applications, especially compared to standard Unity fonts.

In this tutorial, we will explore the differences between Text Mesh Pro fonts and standard fonts in Unity, and explain why Text Mesh Pro is often the preferred choice. We’ll walk you through the process of importing a font into Unity and using it with Text Mesh Pro so that you can use this text rendering solution.

Additionally, we’ll provide recommendations on where to find custom fonts to add a unique touch to your Unity projects.

Whether you’re a game developer, UI designer, or simply interested in optimizing text rendering in Unity, this tutorial will equip you with the knowledge and tools to improve the visual impact of your text elements.

Text Mesh Pro Fonts vs. Standard Fonts vs. “Unity” fonts

Most fonts are stored in one of several formats: TrueType (.ttf), OpenType (.otf), and Web Open Font Format (.woff / .woff2). Under the hood, formats like TrueType describe each character (glyph) using a series of line segments and curves — not pixels.

Unity includes a text renderer by default (i.e., “Unity Fonts”), but it doesn’t look good and offers limited features. Unity’s default text renderer is directly compatible with TrueType and OpenType fonts. You just drag and drop the font into the text renderer. Under the hood, Unity converts the font to a texture atlas and samples that texture atlas during rendering. Unity renders the character glyphs directly to the texture atlas, so the character glyph is scaled to a particular font resolution.

Text Mesh Pro is an alternative text renderer that looks much nicer. It is sometimes abbreviated as TMP. Text Mesh Pro is not directly compatible with these common font formats. Instead, Text Mesh Pro requires you to pre-generate an SDF font atlas, which is a special texture file that Text Mesh Pro can create using a standard font format — TrueType or OpenType. In contrast to Unity’s default texture atlas, the TMP font atlas uses a distance field for each glyph. This approach enables TMP to render fonts more smoothly at varying sizes and also makes it easier to render outlines or other text effects.

In the next section, this tutorial will review how to use Text Mesh Pro to import a standard font format into Unity.

Importing Fonts to Unity using Text Mesh Pro

Overview

With Text Mesh Pro, you can use the power of Text Mesh Pro Fonts, which render as SDFs, to achieve smooth and high-quality font rendering in your Unity project.

It is fairly easy to import a font into Unity for use with Text Mesh Pro.

This section you will learn how to import a font to Unity, how to use Text Mesh Pro to create a font asset, and how to use Text Mesh Pro to generate a font atlas.

Then, we will cover how to create a Text Mesh Pro GameObject and how to apply the Text Mesh Pro font asset to that GameObject.

Install Text Mesh Pro

Text Mesh Pro is included with Unity — you do not need to install anything or import any packages. If you previously removed Text Mesh Pro from your project, you can import it from the Package Manager.

Setup

If you already have a font asset (a .ttf or .otf file) in your project, skip this step.

If you don’t have a font asset in your project, you need to download one. To follow along, download Roboto from Google Fonts now. Go to the Roboto page on Google Fonts: https://fonts.google.com/share?selection.family=Roboto.

Click Download All, then extract the .zip file, and then drag and drop the Roboto-Regular.ttf file from the directory into your Unity project.

Import the .ttf file

You don’t really need to do anything with the .ttf file.

Use Text Mesh Pro to create a TMP Font Asset with the .ttf file

Once you have the font file (.ttf or .otf) imported into your Unity project, create a new Unity Font Asset with Text Mesh Pro.

To import a font into Unity for use with Text Mesh Pro, you need to create a Unity Font Asset using Text Mesh Pro. The Unity Font Asset serves as a container for your imported font, allowing you to leverage its features and apply it to Text Mesh Pro components in your project.

You can use the keyboard shortcut or the context menu to use Text Mesh Pro to create a Text Mesh Pro font asset from the .ttf file that you imported.

To use the keyboard shortcut: Click on the .ttf file, then press CTRL + SHIFT + F12.

To use the context menu: Right click on the .ttf file -> Create -> TextMeshPro -> Font Asset.

As mentioned previously, Text Mesh Pro uses a font atlas to render the glyphs to screen. When you create the Font Asset, Text Mesh Pro does not automatically create the font atlas.

So, you still need to build the font atlas within this Text Mesh Pro font asset in order to use the font with Text Mesh Pro.

Build the Font Atlas

Click on the font asset in your project. In the Inspector, click “Update Atlas Texture”.

Text Mesh Pro will open a new editor window called the Font Asset Creator.

The default settings are mostly fine for now, but you do need to change the Character Set from Unicode Range (Hex) to ASCII or Extended ASCII. The Unicode Range option expects you to provide a list of Unicodes that Text Mesh Pro should import. The ASCII and Extended ASCII options will automatically import all standard font glyphs that are included in the font file. Do that now.

Then, click “Generate Font Atlas”. Text Mesh Pro will quickly generate a font atlas for this font. Once it’s done, click Save. Your font asset is now configured and ready to use.

Create Text Mesh Pro GameObject

To use your new font asset, you need a Text Mesh Pro component in your project.

In your toolbar, GameObject -> UI -> Text — TextMeshPro.

Click on the new GameObject to view it in the Inspector.

Then, assign your Text Mesh Pro font asset to the Font Asset field in the Inspector.

Adding Custom Fonts to Unity

Overview on Finding Fonts

This section will provide you with some examples of websites where you can find fonts for your project. Keep in mind that each font may have a different license, and different websites offer different licensing terms for various fonts.

Google Fonts

Google Fonts has a reliable and large library of open or open-ish fonts. You can use many (most) of these fonts for commercial use. Make sure to check the licenses for any attribution requirements. Google Fonts also has a great set of articles and FAQs on how to choose a good font, how to use your font appropriately, and how to set up hierarchy with fonts.

The League of Movable Type

The League of Movable Type is an open-source font foundry. (A font foundry is an organization that creates new fonts). They have some good stuff. It’s open-source.

Font Squirrel

Font Squirrel is a directory of licensed-for-commercial-use fonts. Many of these fonts are also available on Google Fonts. Pick whichever UI you prefer.

Font Licensing

This is not legal advice. In general, you will want to look for fonts that are licensed under the Open Font License (OFL). These fonts are open-source, so they are free to use for personal and commercial use. You can purchase fonts, but paid fonts can be expensive, and licensing restrictions can be tricky.

System Font Rendering

I briefly covered this during the article, but I’ll reiterate it here. Unity does not use the system font renderer to draw text in the engine. For example, in Windows, most applications use DirectWrite (DWrite), a Direct2D API, to rasterize and render text. Let’s call this the native API. In contrast, Unity has its own API (Text, Text Mesh Pro) that rasterizes and renders the font.

If your font in Unity looks blurry, weird, or different than you expect compared to how it appears on the web, on your desktop, or in the font file inspector, this could be the reason why.

It is possible that Unity does not use DWrite or other system-level font rasterizers for performance reasons or for cross-compatibility and consistency reasons.

Improve Your Unity Projects with Text Mesh Pro Fonts and Unity Font Assets

In this tutorial, we have explored the differences between Text Mesh Pro fonts and standard fonts in Unity, highlighting the advantages of using Text Mesh Pro for enhanced visual quality and advanced typographical options. We’ve walked you through the step-by-step process of importing a font into Unity and creating a Text Mesh Pro font asset, enabling you to use this powerful text renderer.

Additionally, we have provided recommendations on where to find custom fonts, including reliable sources like Google Fonts, The League of Movable Type, and Font Squirrel. These resources offer a wide range of open or open-ish fonts, allowing you to add a personalized touch to your Unity projects.

By understanding the distinctions between Text Mesh Pro and standard fonts, and by leveraging the capabilities of Text Mesh Pro, you can improve the visual impact and readability of text elements in your games or applications.

Remember, while Unity’s default text renderer serves its purpose, Text Mesh Pro provides a superior alternative with its smooth font rendering and extensive features. So don’t hesitate to dive into the world of Text Mesh Pro fonts and unlock the full potential of text in your Unity creations.

Thank you for joining me on this tutorial, and I hope it has empowered you to create visually stunning text elements in your Unity projects. If you have any further questions or would like to delve deeper into game development, feel free to join our game dev Discord server.

Happy text rendering and game development!

Further Reading

A Brief Review of Font Rendering

It’s not a requirement, but it is good to understand what is happening when you render a font glyph — both on your OS and in Unity. Smashing Magazine has written a fairly solid introduction to font rendering.

More on Font Features

Text Mesh Pro offers you the option to enable Font Features. Font Features are advanced typographical options like small caps, ligatures, and tabular (mono-spaced) numerals.

Unity Font Assets Documentation

Unity has good documentation on their manual that covers how to import and use font assets for the default text renderer. I recommend that you never use the default text renderer.

Text Mesh Pro Documentation

Unity has good documentation on their Text Mesh Pro package that covers a whole lot more than what I addressed in this article. If you are going to use Text Mesh Pro (and you should use Text Mesh Pro), then bookmark the documentation and spend some time reading through it.

More on Font Licensing

Overview on Font Licensing

Font licensing is an essential aspect to consider when using fonts in your projects, whether they are for personal or commercial use. Fonts, like any other creative work, are protected by copyright law, which grants exclusive rights to the creator or copyright holder. Understanding font licensing helps ensure that you use fonts legally and respect the rights of font designers and creators.

When selecting fonts for your Unity projects, it’s important to consider the following aspects.

License Types

Fonts are often distributed under various license types, each with specific terms and conditions. The most common font license types include open-source licenses like the Open Font License (OFL), commercial licenses, and freeware licenses. It’s crucial to review the license terms associated with the fonts you use to determine if they align with your intended usage.

Usage Restrictions

Font licenses may have specific restrictions on usage, such as limitations on the number of installations, geographical restrictions, or restrictions on commercial use. Make sure to carefully review the license terms to ensure your usage complies with the font’s license restrictions.

Attribution Requirements

Some fonts require attribution to the font designer or copyright holder as a condition of use. This means you need to credit the font creator in your project, typically by including their name or a designated attribution statement. Be sure to check if the font you want to use has any attribution requirements and fulfill them accordingly.

Redistribution and Modification

Fonts may have restrictions on redistribution or modification. Some fonts may allow redistribution, enabling you to share the font files with others, while others may restrict redistribution entirely. Similarly, modification rights vary depending on the font’s license. It’s crucial to respect these restrictions and only redistribute or modify fonts within the boundaries of the license terms.

Commercial Use

If you intend to use fonts for commercial purposes, ensure that the font’s license permits such usage. Some fonts are specifically licensed for non-commercial or personal projects only. Verifying the font’s license compatibility with your commercial use is crucial to avoid legal complications down the line.

Conclusion

By being mindful of font licensing and adhering to the terms and conditions set by font creators, you can ensure that you use fonts legally and respect the rights of the font design community. When in doubt, review the license information provided with the font or contact the font designer or copyright holder directly for clarification.

Remember, font licensing is important to protect the intellectual property rights of font creators and promote fair usage of their work. So, as you explore and integrate fonts into your Unity projects, be sure to pay attention to font licenses and use them in accordance with the applicable terms and conditions.

Please note that this explanation provides general guidance and is not legal advice. For specific legal concerns regarding font licensing, you should always consult a legal professional or refer to the specific license agreements associated with the fonts you intend to use.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *