GetComponent().text

StarsToUnlock.GetComponent().text = “TEST”;

I’ve got this line setup, of which I’m pretty sure it should work…
StarsToUnlock is referenced as a GameObject, and is set by using GameObject.Find.
No problems finding it, but when the script tries to edit the text on the Text component it just gives a nullreference exception.
The object it searches for is a standard Unity 5 Text object (UI).

Screenshot
Here’s a screenshot of the component, and I made sure it has a unique name, so it’s not finding another gameobject and trying there.

NullReferenceException: Object reference not set to an instance of an object
Password.Start () (at Assets/Portal Minigame/_Scripts/Password.cs:91)

This is the error. The code it’s referencing to is the line stated in the question.

It’s all executed in the Start() function, but I fixed it by putting the code in a if(StarsToUnlock != null) statement…

Anyhow, thanks for helping and eventually leading me to a solution!