Get a Component inside a Component

I have a script attached to GameObject Options and i want to target the component Text and change it’s content, but everything I tried returned Null.

I tried:

public Button button;
public Text txtButton;

changeText() {
button = GameObject.FindWithTag("Button");
txtButton = button.GetComponent<Text>();
txtButton.text = "Something";
}

It always return null (NullReferenceException) when i try do target the Text component inside the Button, but the button itself returns ok.

And here’s the hierarchy, considering that the script is attached to Options GameObject (Inside a Canvas):

![hierarchy

Your hierarchy image didn’t come through, but isn’t the Text a child gameobject of the button? And then that game object has the Text component you want?

So something like…

button = GameObject.FindWithTag("Button");
text = button.Find("Text");   // find child object

txtButton = text.GetComponent<Text>();
txtButton.text = "Something"