9. Why can't I get the text component via GetComponent<TextMeshPro>()?
You can, but there are actually two different types of TextMeshPro
components. Non-UI text components have the TextMeshPro type, as expected
which can be access using GetComponent<TextMeshPro>(). The UI text components
have the TextMeshProUGUI type. You can get those via
GetComponent<TextMeshProUGUI>().
Both TextMesh Pro components inherit from a base class which is
TMP_Text where you can also get a reference to either types of TextMesh Pro
components by using GetComponent<TMP_Text>(). To access these components in
your scripts you will also need to include the "using TMPro;" namespace.
From https: