TextMeshPro
com.unity.textmeshpro
Description
TextMeshPro is the ultimate text solution for Unity. It’s the perfect replacement for Unity’s UI Text and the legacy Text Mesh.
Powerful and easy to use, TextMeshPro (also known as TMP) uses Advanced Text Rendering techniques along with a set of custom shaders; delivering substantial visual quality improvements while giving users incredible flexibility when it comes to text styling and texturing.
TextMeshPro provides Improved Control over text formatting and layout with features like character, word, line and paragraph spacing, kerning, justified text, Links, over 30 Rich Text Tags available, support for Multi Font & Sprites, Custom Styles and more.
Great performance. Since the geometry created by TextMeshPro uses two triangles per character just like Unity’s text components, this improved visual quality and flexibility comes at no additional performance cost.
Tmpro unity как включить
TextMeshPro is the ultimate text solution for Unity. It’s the perfect replacement for Unity’s UI Text and the legacy Text Mesh.
Powerful and easy to use, TextMeshPro (also known as TMP) uses Advanced Text Rendering techniques along with a set of custom shaders; delivering substantial visual quality improvements while giving users incredible flexibility when it comes to text styling and texturing.
TextMeshPro provides Improved Control over text formatting and layout with features like character, word, line and paragraph spacing, kerning, justified text, Links, over 30 Rich Text Tags available, support for Multi Font & Sprites, Custom Styles and more.
Great performance. Since the geometry created by TextMeshPro uses two triangles per character just like Unity’s text components, this improved visual quality and flexibility comes at no additional performance cost.
Установка, добавление, настройка шрифтов с кириллицей в плагин TMPro(TextMeshPro) в Unity
How to Make Damage Text Popups in Unity
Making damage numbers or damage text popups appear above a sprite in Unity, at first glance, seems like a simple one. There are definitely many approaches to this, but one must beware of inefficient, resource intensive or bug-prone solutions.

Motivation — Some Bad Methods
UI Animation
Due to how strongly integrated text and Unity UI are, it seems obvious that a first solution is to render a simple “UIText” object above an enemy sprite — that is, a fully UI based solution. This comes with the rather significant problem of mapping the UI space to the world space, as an enemy at (0,0,0) in world space might have completely different coordinates to place UI on.
Additionally, since the UI Canvas is usually linked to a Camera, if you have a moving camera (say, in a platformer or top down shooter) that tracks the player, you’ll have to offset the position of the text to compensate for the camera motion. Zooming and rotation of the camera produce an even larger problem. Here, by following the UI solution, we need to produce two mappings — World Space to the Moving Camera Space, then from a Moving Camera space to a static camera space, with position, rotation and scaling offsets attuned to the time of instantiation. It’s just too much.
Hardcoding
Instead of this solution, you might also choose to “hardcode” text sprites, and instantiate individual letters or words as sprites, rather than UIText, but this lacks flexibility and requires you to make a new sprite for each number and word, and essentially recreate the whole business of rendering text from sprites of characters (eg. a font) from scratch. I feel like this also is an incorrect approach.
The purpose of this article is to present a better solution to this problem, by leveraging TextMeshPro, and compares the efficacy of Unity’s built in Animation suite, and a procedural, code based approach to the problem.
How Do I Create Floating Damage Text Indicators in Unity?
A solution that I have been using is by using objects that share the Global coordinates that the rest of your game is in, but preserves the flexibility of working with a text processing engine, complete with Rich Text support and myriad additional features. Unity does have a built in “TextMesh” 3D object, but I think that TextMeshPro is the better alternative. It requires first a quick import, and is packaged (free of charge) with the Unity Engine.
Overview
At a high level, we’ll be creating a customizable text object, which will be instantiated above our enemy when our it is damaged. After the text object is instantiated, it will float up and disappear, and then remove itself from the scene by calling Destroy() on itself.
This is the order of events:
- EnemyTakesDamage()
- Instantiate(TextObject parented to Enemy)
- FloatAndFade(TextObject)/Use Unity Animation
- Destroy(TextObject)/Animation Event
Video
Text Tutorial
Setup
This can be installed through the Unity Package Manager (Menu Bar > Window > Package Manager > TextMeshPro > Install).

Then, you can add a non UI text component by going to the menu bar, and creating a GameObject > 3D > Text / TextMeshPro. This will prompt the import of TMP Essentials, which includes a default font and some other useful starting assets, all nested away in a separate folder that you won’t have to worry about.

You can customize this text component to say whatever you like by editing the Text field in the inspector, and you should disable wrapping as this effect is, in my opinion, undesirable in a text popup effect.
Before animating, we should clearly define what sort of effect we’re looking for. My effect will shrink, fade out and move upwards as time passes, eventually becoming invisible by which time it will be destroyed. Let’s break down these effects individually:
To make an object shrink, we must reduce its scale, but for text we can reduce the font size. The default justification is to the upper left corner of the textbox, and I don’t think this looks good as the text appears to translate as you reduce its font size. To prevent this unpredictable scaling, you can set the justification to be centered on both axes.

Fadeout is as simple as setting the Vertex Colour’s alpha to zero, and upwards movement is an increase in the Y coordinate (in 2D space). These are all the required fields for animating.
Why Use Parents?
If we use Unity animation, we must use a Parent gameobject, to hold our text. This is because Unity animation, as far as I know, cannot handle animating local coordinates, and positional animation is done in global coordinates. I made a new empty gameobject and called it “TextHolder”. Now why is this important?
Local coordinates are stated relative to a parent, and global coordinates are stated relative to the scene’s origin at (0,0,0). If we were to animate the position of our text, going from say, (0,0,0) to (0,4,0), these would be global coordinates. We wouldn’t be able to move the text away from these positions in global space, and our text would always spawn and move into the same positions, so instead we must force it to move upwards 4 units in local coordinates by making all coordinates relative to a parent gameobject. Reset the transforms of both objects to (0,0,0).

Animation
To open the animation tab, you can go to Window > Animation > Animation or hit Ctrl + 6 on the keyboard. With the Text (not the holder) selected, create a new animation and call it whatever you like. Then, we can add keyframes by autokeyframing (the red recording button) at 0:00s and 1:00s (a one second long animation). Just set the initial values at 0s for y position, scale and vertex colour, then set the final values at 1s (eg. Y position higher up, smaller font size, vertex colour as transparent)

How to Destroy Gameobject on Animation End
To destroy the gameobject when the animation is done, we have several options, but the easiest is with a hacky method with Animation Events. You can add one by going to the final frame and then hitting the bookmark looking icon. This allows us to call any public method attached to the gameobject being animated, and we can create a simple “self-deletion” script called “DeleteOnAnimEnd.cs” and attach this to the animated text gameobject. We also want to clean up the parent, so we will create a one line function that destroys the parent’s gameobject once called.
Points about Code:
- gameObject, with a lowercase g, references the gameobject that the script is attached to.
- Parents and children are properties of the transform component.
- To get the transform component, or any component, we can use gameObject.GetComponent (), but some special components have shorthand for this, transform with a lowercase t will be shorthand for GetComponent
() and returns a reference to the transform. - To get the parent, we can use the .parent variable, which returns the transform which is a parent to the current transform.
- We can only destroy gameObjects, not transforms on their own, so to get the attached gameobject to the transform, we can use the .gameObject property of a transform.

If we set this as the function to be called at the animation event, (make sure to click the little bookmark in the timeline) we will have it trigger the DestroyParent() function at that frame, and thus destroy the parent (and child) gameobject.
Prefabbing
Prefabs in Unity are useful to create extensible, multipurpose and instantiable content. We can drag the textholder gameobject from the hierarchy into the project tab to create a prefab. Then, if we drag out the textholder prefab into the scene, we’ll see it is regenerated.
Enemy
Our enemy can be anything, it’s just a 2D sprite in this case that will have something spawn on top of it.

To imitate damage, well create a new script that detects when the player presses the X key on the keyboard, then instantiates the damage text over the enemy’s head with a customizable string. I called it GameManager.cs, and the code is below.
Points about Code
- We need references to the prefab, enemy and a public (exposed) string to display. This should be set in the inspector to the correct values.
- We must** import TMPro**, as seen on line 4, in order to manipulate textmeshpro objects
- Instantiate() has several overloads, the one I’m using is (gameObject, parentTransform). The enemy is parent so the damage text will inherit its position, velocity, etc.
- To manipulate our instantiated gameobject, we must place it in a variable. Instantiate() returns a reference to the instance.
- To access the actual damage text, we must get the child of the prefab, which is obtained by .transform.GetChild(0), then we can get to the textmeshpro component which allows us to set the text to our custom string.
To activate this code, we’ll have to attach it to something in our scene. I suggest the main camera.
Then, play the scene and test it out! This is the end of the standard animation part of this tutorial.
Advanced: Animation from Code
For a more advanced and flexible technique, we can do everything from code, with means we can easily adjust the start and end colour, height, scale and other properties from code, rather than by adding new keyframes. The following code will permit you to do so, simply add this to a textmeshpro Text gameobject, and set the properties. No parenting is required. You can turn the gameobject, with this component, into a prefab and instantiate it the same way as above, but we can change the line
as we no longer need the child reference.
Procedural Code
We are taking advantage of the LERP function to smoothly transition from an initial to final state, controlled by a progress variable which is affected by the total time passed divided by the duration of the animation. As this is altogether more complex than the other techniques I explore, I will make a separate guide on this in the future. For now, I suggest you only use this code as a jumping off point, and I have no guarantees that it will work 🙂
Conclusion
While there are many esoteric ways of creating a hit indicator, damage text and crit marker in Unity, I think instantiating an animated TextMeshPro text is the easiest way, but it can be a bit inflexible so a procedural approach to circumvent the animation component can produce more desirable results, with more skill and effort applied.
TextMeshPro
com.unity.textmeshpro
Описание
TextMeshPro — это идеальное текстовое решение для Unity. Это идеальная замена текстовому интерфейсу Unity и устаревшей текстовой сетке.
Мощный и простой в использовании TextMeshPro (также известный как TMP) использует расширенные методы визуализации текста вместе с набором пользовательских шейдеров; обеспечивая существенное улучшение визуального качества, а также предоставляя пользователям невероятную гибкость, когда речь идет о стилизации текста и текстурировании.
TextMeshPro обеспечивает улучшенный контроль над форматированием и макетом текста с такими функциями, как интервалы между символами, словами, строками и абзацами, кернинг, выравнивание текста по ширине, ссылки, более 30 тегов форматированного текста, поддержка нескольких шрифтов и спрайтов, пользовательские стили и многое другое.
Отличная производительность. Поскольку геометрия, созданная TextMeshPro, использует два треугольника на символ, как и текстовые компоненты Unity, это улучшенное визуальное качество и гибкость не требуют дополнительных затрат на производительность.
How to write a Text Mesh Pro text from Script in Unity
In this article we will see how to work with the Text Mesh Pro components from a Script, in addition you will find a video from the channel in which we will create a TEXT OBJECT to display in a Canvas and another Text Mesh for the 3D space and we will create a Script inside which we will modify the text that these components show, as an extra we will also modify the color by code.
Text Mesh Pro has now become the standard solution for displaying text in Unity, replacing the Text Mesh component for displaying text in the 3D view and the Text component for adding text in the UI. The old Text Mesh and Text components can still be used, only that they are in a «Legacy» section, this is indicating that it is preferable to use Text Mesh Pro and perhaps later the old components will no longer be available.
Fig.1: The Text component has been moved to the «Legacy» section.

ABOUT THIS VIDEO
In this video we see how to SETUP TEXT MESH PRO in Unity and how to write a Text Mesh Pro text in Unity through code.
Dear reader
In the channel there lots of videos about Blender, Unity and programming
in which we solve different problems and we provide useful information on these topics.

Creating Text Mesh Pro objects for World Space and Canvas
We start by creating the Text objects that we will later modify from a Script, we are going to create two types of Text Mesh Pro objects, one to use in the user interface and another to use as a 3D object in the scene.
Creating Text Mesh Pro Text for the user interface
In Unity the Text Mesh Pro objects that are in the UI section must be placed as children of a Canvas object, so let’s assume that we already have one of these objects in the scene. To create a new Text Mesh Pro object we go to the hierarchy, right click on the Canvas (or any child object of the Canvas), go to the UI section and choose the «Text — Text Mesh Pro» option, as shown in figure 2.A.
Fig. 2.A: Option to create a new Text Mesh Pro text for the user interface.
Creation of Text Mesh Pro Text for World Space
The other option to write text on the screen is to use a Text component of Text Mesh Pro as a 3D object and therefore located in a position in the world, this object will be found in the «3D Object» section of the creation window, as shown in figure 2.B.
Fig. 2.B: Option to create a new Text Mesh Pro text as a 3D object in the scene.
MOST SEARCHED VIDEOS FROM MY CHANNEL
ABOUT UNITY
ABOUT BLENDER
First time using Text Mesh Pro
In case we have not configured Text Mesh Pro yet, we will get the window shown in figure 3 where we will be given the option to import the necessary components to use Text Mesh Pro, we click on «Import TMP Essentials», as shown in figure 3. The second button to import examples and extras is optional.
Figure 3: Window for importing Text Mesh Pro package into Unity.
Result of the creation of objects
Once the objects were created, I made a few modifications in the inspector (font size, text) and the result is as follows:
Fig. 4.a: Text Mesh Pro objects in the hierarchy.
Fig. 4.b: Text Mesh Pro objects displayed in the scene.
Once the objects have been created and Text Mesh Pro imported we can start using the Text Mesh Pro Text component from the inspector or write it through a Script. In figure 5 we see the Text component in the Inspector window, it has many more configuration options compared to the old text solution.
IMPORTANT
In figure 5 we see the field to edit the text that appears on the screen, currently has written the value «Canvas Text», that is the field that we want to edit by code and to do it we will have to edit a variable called «text» that is define in that component.
Fig. 5: Text Mesh Pro component in the inspector.
Script for writing text in Text Mesh Pro component
In order to write a Text Mesh Pro component by code I will create a script and assign it to some GameObject of the hierarchy, as shown in figure 6. In this case my script is called «ModifyTextMeshPro», inside this script I will modify the texts.
Fig. 6: We create a script and assign it to some object in the hierarchy.
Import TMPro namespace in our Script
To be able to use the Text Mesh Pro components comfortably, it is convenient to import the «TMPro» namespace by adding in the header of our script the line «using TMPro;» as shown in figure 7.
Fig. 7: We declare that we are going to use the namespace «TMPro» in the header of our script.
Declaration of the variables to be used
We are going to declare two variables of type «TMP_Text» where the references of the Text components that we want to modify will be stored, in this case the names of my variables will be «canvasText» and «worldText», in these variables I will place the Text Mesh Pro Text components of the canvas and the world space respectively.
DETAIL
The names «canvasText» and «worldText» are the names I chose for these variables, you can use any other name as long as it contains the allowed characters.
Fig. 8: Declaration of the variables to be used to modify the Text Mesh Pro text.
Initialization of variables (Assignment of references)
The initialization of this type of non-primitive variables is crucial, if we do not take care of putting inside the variable the precise object we want to refer to, we will get a null reference exception.
There are many ways to initialize the variables, in this case I will do it in one of the simplest ways which is by dragging the GameObjects that contain the Text components I want to modify to the variable spaces in the inspector.
Fig. 9: The appropriate GameObjects are dragged into the spaces in the inspector to initialize the variables.
The declared variable does not appear in the inspector
In the case that the variable does not appear in the inspector it is usually because its visibility is private, it can be solved by declaring the variables as public as shown in figure 8, adding the word «public», or they can also be declared as private but indicating that they are serialized by the inspector, as follows:
[SerializeField]
TMP_Text canvasText;
[SerializeField]
private TMP_Text canvasText;
Another reason why the variables do not appear in the inspector can be when there are errors in console and the changes made in the scripts are not updated, to solve this we will have to solve all the errors that there are in console, once made this Unity will compile and the new modifications will appear.
Code instructions for modifying Text Mesh Pro text via Script and tests
Once we have initialized the variables we can use them, in this case if we want to modify the text displayed by the Text Mesh Pro component, we must modify the variable «text» defined inside it, for this we use the dot operator that allows us to access the variables and public functions defined inside an object,
Fig. 10.A: Writing a Text Mesh Pro text from a Script in Unity.
Fig. 10.B: Pressing play shows how the texts on the screen are modified.
Extra: Change the color of a Text Mesh Pro text by code
Fig. 11.A: In lines 22 and 23 the color of the Text Mesh Pro texts is changed by code.
Fig. 11.B: When pressing play we can see how the colors of the texts on the screen change.