Hello. We’re creating all of our text at runtime. We have a loading period where we load all of the assets needed for a certain screen i.e. textures, fonts, etc. However, I notice that the first time we create a text takes way much longer than the second time or any time after. I wonder if we need to load something else other than the font we use to create the text?
public class TMP_Test : MonoBehaviour
{
async void Start()
{
var font = Resources.Load<TMP_FontAsset>($"Fonts & Materials/Bangers SDF");
await Task.Delay(1000);
var sw = Stopwatch.StartNew();
var txt0 = CreateText("txt0", "Hello World!", font);
Debug.Log($"txt0 - ms: {sw.ElapsedMilliseconds} t: {sw.ElapsedTicks}");
await Task.Delay(1000);
Destroy(txt0);
await Task.Delay(1000);
sw.Restart();
CreateText("txt1", "Hello World!", font);
Debug.Log($"txt1 - ms: {sw.ElapsedMilliseconds} t: {sw.ElapsedTicks}");
}
GameObject CreateText(string name, string text, TMP_FontAsset font)
{
var go = new GameObject(name);
var tmp = go.AddComponent<TextMeshPro>();
tmp.font = font;
tmp.isOrthographic = true;
tmp.rectTransform.sizeDelta = new Vector2(200, 50);
tmp.text = text;
return go;
}
}
I get these results running the code above:
If we’re going to create all our text dynamically at runtime, what are the best practices of going about doing this approach?
Thanks in advance!