Noticed this while working with my son last night on the RollABall tutorial, decided to use the new UGUI system and this bug has occured on a couple projects now.
Simple to reproduce, here’s the details:
...
using UnityEngine.UI;
...
public Text scoreLabel;
....
void Update( )
{
scoreLabel.text = "Score: " + Time.frameCount;
}
So what happens is that the value is set to inspectors initial value, then on run it updates once to say, “Score: 0”, afterwards the value will remain “Score: 0” and never change.
I’m running the 5.0 pro beta and my son is trying 4.6 basic beta - problem seems to exist in both cases.
Are we missing a “Repaint()” kind of call here or is this a bug?
I’ll package up his project and report/send it to you - but basically we’ve changed the code to use OnGUI() and have no problems, but reverting back to uGUI the problem comes back. Don’t believe we have any side effects or logic errors that are causing this, will try again tonight and get back to you on it.
EDIT: To provide a little more information I see this when setting an InputField.text. The value is set but it does not display unless I ‘touch’ the component (e.g. change something else on the component in the editor).
For me on RC2 it is only Text.text. What is interesting is the inspector text area gets updated but the render doesn’t update to show the new text, but if you move the object around in the game view then its like the render resets and shows the new text.
Also Every time I try to do anything like this "vartext.text = “whatever”
i get a nasty error message.
get_enabled can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
I am not doing anything special. Just updating text on a button click.
Hmm so i set up a simple test pretty much using what Lypheus had posted. On a button click up update the text. Everything seems to work as expected for me. using latest source code so post RC3 stuff
@charmandermon The fact you get a error message is likely the reason your text doesnt update. Its a quirk with unity that error message (depending on severity) can cause the rest of the function to not execute. What else are you doing in the function where you set the text?
Right before it I check the input.text areas and set them to variables.
Then I set a text.text and I get the error message. When I comment out the Text.text = string line then I don’t get an error.
I even tested it with just a simple text.text = “hello” and sure enough it errors. I am currently on the windows version. RC2. I tried building to web, standalone, and ios. All error, and don’t render the text.text unless I move the object in the game view. This did work a few versions back. If you want I can make a repo build.
DOES NOT WORK ON:
Windows Editor
IOS Build (On Device)
WORKS ON:
Mac Editor
Mac Builds
Also I figured out my error message I was getting earlier so you can ignore that part, it had nothing to do with the GUI system. It was because I had a separate login thread running and you can’t access unity elements from a separate thread. But it is alarming that label updating doesn’t work on certain instances.
i’m really curious about the differences between our systems as it the project you send me work for windows editor, ios, mac editor. I’m not sure whats going wrong.