TMP & UI.Text together

Hi there,

Does TextMeshProUGUI inherit UI.Text? If no, is there any way to use them both in the same method? Common interface maybe?

I’m trying to refer their text field to replace its string dynamically.

At the moment I use solution like one below:

foreach(var go in gos){
            var tmPro = go.GetComponent<TextMeshProUGUI>();
            var uiText = go.GetComponent<Text>();

            if(tmPro == null && uiText == null)
                continue;

            if (tmPro != null)
                tmPro.text = newText;

            if (uiText != null)
                uiText.text = newText;
        }

but it’s pretty ugly, I’d prefer something more elegant

TextMesh Pro was designed as a replacement for UI.Text. There is no inheritance between the two.

The TextMesh Pro components which are and inherit from TMP_Text.

What is your use case for using both TextMesh Pro and UI.Text?

I’ve got the project with a lot of UI elements in it. Some of them use TMP, the rest ones use UI.Text. So answer to your question is “original design”

I believe there are some conversion utilities around written by TMP users to convert projects using UI.Text to TextMesh Pro.