Label - Text Updates Failing?

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?

it should update any time the text changes. any chance Time.frameCount doesnt update or you’ve disabled the script?

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.

I see this problem with release candidate 2 also.

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).

Is this only on Input field? If so we have a fix that will get to the patch release.

if its just a Text.text then thats a different issue.

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.

Trying this on 5.0 and it was working with a simple Time.frameCount test - will test again this weekend with sons project to see whats up.

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?

Another approach Phil - charmandermon could confirm that by using a try … finally block and ensure the finally block has the text update inside it.

Try this:

blahCount ++;

try {
    .... your code ...
}
finally {
    myText.text = "Blah: " + blahCount;
}

Just a thought - I’ll have more feedback on my end after the weekend.

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.

yes please make a repo build as i dont know what could be going wrong.

PMing now

More info on label Updating using RC3

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.

I’m facing the same issue, any updates?