[Solved] UI Text not updating C#

I’ve been having this problem for a while now but it only seems to happen in this project. When I try and use the Text.text function in Unity it doesn’t update the text. However, after I stop the game and play it again then the text I am trying to change changes to what I was trying to change before. For instance, if I am updating the score it won’t register the update in the text until I restart. Here are a couple of scripts that aren’t working.

Have you checked to see if you are changing a prefab instead of the object in the hierarchy?

If so then you can drag the prefab out of your project window into the heirarchy. You should now have a blue object in the heirarchy which is a copy of your prefab. Use that in your game instead of the prefab.

Delete the “public” in “public Text GoldText;”. Be very careful with public variables, can lead to very hard to find bugs where you think you are assigning a value in code but you also changed it in the inspector and it is serialised. I wish Unity didn’t use public to do this!

Note you are assigning GoldText with the line “GoldText = GetComponent ();”. This is fine if this script is actually on your Text object in the inspector. If it isn’t then this is your bug.

Note both of the above are assigning GoldText with values, one of them is very probably your bug.

Have you assigned the Text variable in the Inspector?
If so, then are you using TextVariable.text = "Your string here";?