Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Label - Text Updates Failing?

Discussion in 'UGUI & TextMesh Pro' started by Lypheus, Nov 19, 2014.

  1. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    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:

    Code (csharp):
    1.  
    2. ...
    3. using UnityEngine.UI;
    4.  
    5. ...
    6. public Text scoreLabel;
    7.  
    8. ....
    9. void Update( )
    10. {
    11.     scoreLabel.text = "Score: " + Time.frameCount;
    12. }
    13.  
    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?
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    it should update any time the text changes. any chance Time.frameCount doesnt update or you've disabled the script?
     
  3. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    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.
     
  4. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106
    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).
     
  5. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  6. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    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.
     
  7. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    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.
     
  8. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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?
     
  9. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    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:

    Code (csharp):
    1.  
    2. blahCount ++;
    3.  
    4. try {
    5.     .... your code ...
    6. }
    7. finally {
    8.     myText.text = "Blah: " + blahCount;
    9. }
    10.  
    Just a thought - I'll have more feedback on my end after the weekend.
     
  10. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    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.
     
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    yes please make a repo build as i dont know what could be going wrong.
     
  12. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
  13. charmandermon

    charmandermon

    Joined:
    Dec 4, 2011
    Posts:
    352
    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.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    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.
     
  15. KNDL

    KNDL

    Joined:
    Nov 25, 2014
    Posts:
    1
    I'm facing the same issue, any updates?