Unity - Manual: Font (2024)

  • Unity Manual
  • Graphics
  • Graphics Reference
  • Mesh Components
  • Text Mesh
  • Font

Text Asset

Texture Components

Switch to Scripting

Fonts can be created or imported for use in either the GUI Text or the Text Mesh Components.

Importing Font files

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.

Unity - Manual: Font (1)
Property:Function:
Font SizeThe size of the font, based on the sizes set in any word processor.
Rendering modeThe font rendering mode, which tells Unity how to apply smoothing to the glyphs.
CharacterThe 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 DataThis 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 NamesA 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. Adjusting the font size effectively changes how many pixels are used for each glyph in this generated texture. Text Mesh 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.

Unity - Manual: Font (2)

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.

Kerning can be set to define 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.

Unity - Manual: Font (3)

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 256x128, 4 characters across, 2 down (so 64x64), 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 128x128, putting 128 and –128 into the Vert Width and Height will give properly proportioned letters. Vert Y must be negative.

Width will be the width of your character in pixels.

Unity - Manual: Font (4)

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 GUIText or Text Mesh, you can enter unicode characters into the Component’s Text field in the Inspector.

You can also use unicode characters if you want to set the displayed text from scripting. The Javascript and C# compilers fully support Unicode based scripts. 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, a GUIText, 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.

GUIText and Text Mesh

If you are using a GUIText or a Text Mesh, you can change its color by using a custom Material 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.

UnityGUI

If you are using UnityGUI scripting to display your font, you have much more control over the font’s color under different circ*mstances. To change the font’s color, you create a GUISkin from Assets > Create > GUI Skin, and define the color for the specific control state, e.g. Label > Normal > Text Color. For more details, please read the GUI Skin page.

Hints

  • To display an imported font select the font and choose GameObject > Create Other > 3D Text.
  • You can reduce the generated texture size for fonts by using only lower or upper case characters.

Text Asset

Texture Components

Unity - Manual: Font (2024)

FAQs

How to add a custom font in Unity? ›

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

How do I change font style in Unity? ›

To change the font, you must create a Font Asset via the Font Asset Creator. To access the Font Asset Creator, select Window | TextMeshPro - Font Asset Creator. This will allow you to convert a font file to one usable by TextMesh Pro.

What is the default font for Unity project? ›

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.

How do I import my own font? ›

Add a font
  1. Download the font files. ...
  2. If the font files are zipped, unzip them by right-clicking the .zip folder and then clicking Extract. ...
  3. Right-click the fonts you want, and click Install.
  4. If you're prompted to allow the program to make changes to your computer, and if you trust the source of the font, click Yes.

How do I install custom fonts? ›

Go to Settings > Display > Font style. Tap Download fonts. Select the font that you want to install. Tap Install.

How do I use custom font text mesh Pro unity? ›

From the menu, choose: Window > TextMesh Pro > Font Asset Creator to open the Font Asset Creator. Choose a Source Font File. This the Unity font Asset that you want to convert into a TextMesh Pro font Asset. The atlas, and information about the font Asset appear in the texture preview area.

What Fonts does unity have? ›

Unity Editor uses Inter as the primary font family on every platform. Inter is a font family designed to accommodate dense interfaces. There are secondary fallback options that vary per OS that can be used if Inter cannot be used.

How do I change my font style code? ›

To change font type purely with HTML, use the CSS font-family property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag. This approach to changing font type in HTML uses the style language CSS.

Can I create my own font? ›

You can design font characters using a vector design app like Adobe Illustrator or Inkscape and various font creation tools. Once you design your font letters, you can turn them into a font using font software like FontForge, Birdfont, FontLab, or Glyphs. The most common font file types are TrueType Font (.

Is it legal to convert OTF to TTF? ›

In most cases, no. This will depend on the actual EULA though, as with any other software product. Legally, font files are software. I don't know of too many foundries allowing font conversion though (read: practically none).

Can I edit a TTF font? ›

Birdfont – A free font editor for TTF, OTF and SVG fonts.

What coding style does Unity use? ›

Camel case and Pascal case are common standards in use, compared to Snake or Kebab case, or Hungarian notations. Our guide recommends Pascal case for public fields, enums, classes, and methods, and Camel case for private variables, as this is common practice in Unity.

What is the maximum font size in Unity? ›

The Unity font API itself has a limit of 500 point size whereas UI. Text is limited to 300 point as you discovered. The maximum font atlas texture size is 4096 X 4096 which is too small to hold the full ASCII set at 500 points. For most fonts, when using static (ie.

What is Unity editor written in? ›

Unity (game engine)
Developer(s)Unity Technologies
Initial release1.0 / June 8, 2005
Stable releaseUnity 2023.2.17 (Tech Stream) Unity 2022.3.24 (LTS) / April 4, 2024 April 9, 2024
Preview releaseUnity 6000.0.0 Beta 15 (Beta) 2023.2.0a22 (Alpha) / April 13, 2024 July 10, 2023
Written inC++ (runtime) C# (Unity Scripting API)
6 more rows

How do I add custom fonts to CSP? ›

Go to [Text] > [Tool property], tap [Add font from files…], and select the font file you would like to add.

How do I add custom fonts to cargo collective? ›

Open the font menu, click on the “Custom” link at the top, and then on “Add Fonts”. Here you can drag & drop your font files or paste your embed code. Click OK to add the fonts to the font menu. If you're uploading fonts from your desktop, the font files will be added to your Files (which has a 100MB limit).

References

Top Articles
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6304

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.