Difference between TextMeshPro and TMP_Text?

I am used to (from other tutorials) using the class TMP_Text to manage Text Mesh Pro Text, insted of the class TextMeshPro used in this chapter of the course. Using this approach worked perfectly.

Are they different, are they interchangeable?

Here is the code I made:

using TMPro;
using UnityEngine;

public class GridDebugObject : MonoBehaviour
{
    [SerializeField] private TMP_Text gridText;
    
    private GridObject gridObject;
    
    public void SetGridObject(GridObject gridObject)
    {
        this.gridObject = gridObject;
    }

    private void Update()
    {
        gridText.text = gridObject.getGridPositionString();
    }
}

The TMP_Text class is the parent class of both the TextMeshPro and TextMeshProUGUI.
As we’re only using the .text property, then the TMP_Text reference could be used in place of the TextMeshPro or TextMeshProUGUI components, as you can assign any child class to a field of the parent class.

2 Likes

Understood. Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms