getComponent Question

Hello,
I have a canvas as an UI-Element to display properties of a game-element.
For every property I want to create manual a Text (I use Text Mesh Pro).

If a Gameobject creates now a copy of this UI-prefab, I want to “fill” the text with the properties of the Gameobject.
I got the properties. But I can’t “adress” the Text in a right way:
I have my canvas, which got this script:

public class Canvas_TankControl : MonoBehaviour
{
    Tank tank;
    public TextMeshPro tmp_tankName;
    public void init(Tank _tank)
    {
        Debug.Log(_tank.name); // this gets the name correct!
        tank = _tank;
        TextMeshPro[] tmps;
        tmps = this.GetComponents<TextMeshPro>(); // I hoped to get on this way all TextMeshPro-Texts
        Debug.Log("tmps.Length: " + tmps.Length);  // this results in zero "catches"
        foreach(TextMeshPro tmp in tmps)
        {
            if(tmp.name == "tmp_tankName") // if the name of the TextMeshPro is "xy" fill it with the correspondent property
                tmp.text = tank.name;
        }
    }

This is the prefab:

I hope, someone can help me. The components are still a riddle wrapped up in an enigma for me :hushed:

As far as I can see the Text is a child of the object that has your Tank script.
So try GetComponentsInChildren<> instead.

Thanks for your help!
It works now!
Your hint and the fact, that in TMP there are two text-types: TextMeshPro and TextMeshProUGUI. You can acces their text with TMP_Text (http://digitalnativestudios.com/forum/index.php?topic=890.0 No. 9).
BTW: I love your train-sounds :smiley:

Thanks a lot mate.
Glad I could help