I'm trying to create a UI in Unity using C# which displays some attributes from a player, however I am getting a NullReferenceError regarding the Text objects. I'm not sure why this is happening because there isn't anything which should be deleting these objects during runtime, and I'm fairly certain the objects are being located properly.
I have two objects being used almost identically, just for two different variables: When the program starts it locates them using:
starstxt = GameObject.Find("Stars").GetComponent<Text>();
My understanding is that this should find the text object in the scene with that name (of which there is only 1).
Then to display it:
starstxt.text = ($"Stars: {stars}");
"stars" is a variable accessed from the player.
This is the line the error is occuring on, does anyone know why? This is the only time this object is used/referenced in the program.