get Text of GameObject ,Get one fo multiple TextMeshPro of Button

so I got a Button, which has two TextMeshPro and an image. I want to change the text of the one TextMeshPro, but I can’t get it in the code. I tried the following, but it didn’t work:

197810-buttons.png

button.GetComponentInChildren(typeof(TextMeshPro)) as TextMeshPro
button.GetComponent()
also with Text, TextMesh as Properties for the GetComponent, but also no success. I also tried to get it form the Component with a script but it always says that it is null. Can someone help?

,I got a button, which has two TextMeshPro Items and an image. I can get the button from the panel. Now I want to change the text in the amount TextMeshPro, but it is always null,

I can get the amount Rect Transform with

button.Find(“Amount”)

But I can’t add

.GetComponent()

to get the text. I also tried

GetComponentInChildren()

but that also doesn’t work. Has some an idea who I can change the text?
I also tried to get it within the Gameobject ‘amount’ itself, but there is the same problem…

var list = button.GetComponentsInChildren(true).ToList() //Linq
var text = list.Find(x=>x.name == “Amount”)
text.text = “Test text”

But it’s easier to create a script in which you can store all TMP_Text and not use GetComponent.

I found it out myself. The problem is that I used ‘TextMeshPro’ instead of ‘TextMeshProUGUI’ which was the reason I coun’t find the corresponding text field…super studip mistake.