Font assets act as containers for fonts. With font assets, you can import fonts into your projects and create variations of a font from one file and not change the original font. Another reason to create font assets is to deal with languages with massive character sets, such as Chinese. You can include only the characters you need, rather than the full set of characters.
You can convert TrueType (.ttf
), OpenType (.otf
), or TrueType Collection(.ttc
) fonts to font assets. A font asset includes a font atlas texture file that contains all of the characters. There are several atlas populate modes and render modes to choose from when you create a font asset.
TextCore supports the Static, Dynamic, and Dynamic OS atlas population modes.
Static font assets pre-bake characters into the atlas texture during conversion. Use static font assets to contain known text in your project, such as labels and section titles. When you create a static font asset, the font atlas is empty by default. You must manually generate the font atlas and include all the characters required for the project. The project build doesn’t require you to include the font source file, so it’s fast and efficient.
Refer to instructions on how to create a Static font asset.
Dynamic font assets start with an empty atlas texture. Dynamic font assets look for characters in the source font file and adds the characters dynamically as you use them in a UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary. Use Dynamic font assets for unknown text in your project, such as any text input fieldsA field that allows the user to input a Text string More info
See in Glossary. Dynamic font assets are flexible, but they have additional performance overhead because the project build requires to include all source font files.
See instructions on how to create a Dynamic font asset.
Dynamic OS font assets are a dynamic font asset that references the font file on the operating system instead of the source font file. Compared to the Dynamic font asset, dynamic OS font assets have less memory overhead. The project build doesn’t require to include the font source files. Make sure that the fonts are on the operating system of the targeted platforms. Dynamic OS font assets are great candidates for fallback font assets.
To create a dynamic OS font asset, import the font from the operating system to your project, and use it to create a dynamic font asset and change the Atlas Population Mode to Dynamic OS.
TextCore supports atlas render modes for bitmap and Signed Distance Field (SDF).
Bitmap rendering generates font assets that perfectly align each pixelThe 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 of the font with the sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary and GUI pixels. Use the following render modes for pixel art:
SDF rendering generates font assets that look crisp when you transform or magnify them. SDF rendering supports effects such as outlines and drop shadows.
Unlike bitmap font textures, SDF font assets contain contour distance information. In font atlases, this information looks like grayscale gradients that run from the middle of each glyph to a point past its edge. The gradient’s mid-point corresponds to the edge of the glyph.
The images below show bitmap and SDF font assets and the rendered text they produce. The bitmap fonts produce text whose edges are more or less jagged and blurry, depending on how far the text is from the cameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary, and how it’s transformed and distorted. The SDF font produces text with smooth edges regardless of the distance from the camera.
Use the following render mode for SDF fonts:
If you want to make changes only to a font asset’s metrics, instead of creating a new font asset, create a font asset variant based on another font asset. A font asset variant can have styling that distinguishes it from the original font asset, without consuming extra space for textures. The variant stores its own Face Info, Character, Glyph, and Adjustment Pair data, but still refers to the original atlas.
To create a font asset variant, right-click the font asset and select Create > Text> Font Asset Variant.
Characters in the font texture need padding between them so they can be rendered separately. This padding is specified in pixels. Padding also creates room for the SDF gradient. The larger the padding, the smoother the transition, which allows for higher-quality rendering and larger effects, like thick outlines. Use a padding of 5
for a 512x512
texture. A good rule of thumb is to have a sampling-to-padding ratio of 1:10
.
For most fonts, use a 512x512
texture resolution if you include all ASCII characters. To support thousands of characters, use large textures and enable Multi Atlas Textures in the font asset’s InspectorA 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 window. This automatically creates new textures of the same size once the main texture is full.
You can also enable Multi Atlas Textures if you design for mobile devices, where an imposed maximum texture size prevents an entire set of glyphs from fitting in a single atlas of sufficient quality.
To use a font asset, in UI Builder, select the font from Font Asset in the Inspector window.
Note: The Font field is for backward compatibility. If you want to use a font from the Font list for your legacy projects, you must select None from Font Asset. Otherwise, the font you selected from Font won’t take effect.
You can apply a font asset to a text element in USS with the following syntax:
-unity-font-definition: <resource> | <url>
For example:
Label { -unity-font-definition: url("/Assets/UI Toolkit/Resources/Fonts & Materials/LiberationSans SDF.asset"); }
For more information, refer to USS text properties.
In summary, consider the following when you create a font asset:
1:10
.Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.