# Best Practices

{% hint style="info" %}
Every project is different, but in this page you can find some common best practices that can help you set up everything better and avoid most common issues!
{% endhint %}

### Use Text Animator "SetText/ShowText" methods instead of TMPro

If you're setting text via code, please use Text Animator or its typewriter directly instead of TextMeshPro.

```csharp
// Some code
TMP_Text tmpText;
Febucci.UI.Core.TAnimCore textAnimator;
Febucci.UI.Core.TypewriterCore typewriter;

// [...] do this
textAnimator.SetText(value); // to set the text instantly
//or 
typewriter.ShowText(value); // to set it if you have a typewriter
```

API of reference: [textAnimator.SetText](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Core.TAnimCore.html#Febucci_UI_Core_TAnimCore_SetText_System_String_), [typewriter.ShowText](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Core.TypewriterCore.html#Febucci_UI_Core_TypewriterCore_ShowText_System_String_)

***

### Set the entire text/dialogue only once

Please try to set text just once, and use the typewriter / visibility methods to control how it appears.

{% hint style="info" %}
If you really need to append text later in time, you can use the "textAnimator.AppendText" method.
{% endhint %}

<details>

<summary>Example</summary>

If you have a character that says "Helloooo how are you doing?", and you want to display it letter by letter, simply do: `typewriter.ShowText("Hellooooo how are you doing?");` and that's it! [Show and hide letters dynamically](/text-animator-unity/2.x/typewriter/show-and-hide-letters-dynamically.md)

***

If you're building a dynamic string, you can still do that before setting its value to the typewriter/animator.

```csharp
int apples = 5; //later taken from the game state
string playerName = "Bob";

// build the entire dialogue line first
string dialogue = $"Hello {playerName}, you've got {apples} apples";

// then set the text once
typewriter.ShowText(dialogue);
```

(If you're using a Dialogue System, they'll do this for you - no worries ! [Integrations](/text-animator-unity/2.x/integrations/integrated-plugins-and-dialogues-systems.md))

</details>

<details>

<summary>Why should I set the entire text once, instead of character by character?</summary>

Performance! (Even if you didn't have Text Animator.)

Every time you set the text, TextMeshPro needs to calculate its mesh, positioning etc., and Text Animator has then to re-calculate character durations and more. This means that if you change it multiple times per second (e.g. adding more letters), you're doing these calculations every time.

To display characters one by one, you can simply set the full text once, and then start the typewriter: [Show and hide letters dynamically](/text-animator-unity/2.x/typewriter/show-and-hide-letters-dynamically.md)&#x20;

</details>

***

### Use TextAnimator's "ScheduleMeshRefresh" instead of TMPro.ForceMeshUpdate()

If you call "tmpText.ForceMeshUpdate", TextAnimator might lose some references and not display letters correctly. If something changed in the text that makes you want to call that function, please try calling TextAnimator "ScheduleMeshRefresh" instead! \[[Scripting API](https://www.api.febucci.com/tools/text-animator-unity/api/Febucci.UI.Core.TAnimCore.html#Febucci_UI_Core_TAnimCore_ScheduleMeshRefresh)] It'll perform that method on the next frame, but keep all references intact.

***

*If you're changing something in the text inspector but it's not getting updated, please let us know!*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.febucci.com/text-animator-unity/2.x/other/best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
