Search Unity

Canvas UI Text - Not Updating (Unity 2019.1.0f2)

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by Plumpman, Apr 18, 2019.

  1. Plumpman

    Plumpman

    Joined:
    Sep 7, 2012
    Posts:
    24
    I'm getting a major issue with Canvas UI Text in Unity 2019.1.0f2.
    All my text fields are no longer updating reliably when setting them through code.

    My text is properly being set, and I can see it in the text's inspector, but its not reflected in the editor or game view because the canvas doesn't want to refresh itself. It thinks nothing has changed and so doesn't update the text fields. If I go to my Canvas and change the Canvas Scaler Reference Resolution around, it then forces an update and all my text is updated in editor and game view.

    EDIT: Changing the Main Canvas (root) object's hierarchy also triggers a refresh.
     
    Last edited: Apr 18, 2019
    mimicryArt likes this.
  2. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    120
    I've had this happen in 2019.1.2f1 too. Not text, changed color of an Image and the color didn't change. Later even tried disabling and entire UI GameObject and it just stayed there, not disappearing at all.
     
    mimicryArt likes this.
  3. N_Murray

    N_Murray

    Joined:
    Apr 1, 2015
    Posts:
    98
    I've had this problem a few times and moving the UI code to late update instead of update usually fixes it for me. I hope it helps
     
  4. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    460
  5. sampenguin

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    18
    I just ran into this issue with a Text component .text not rendering correctly in 2018.3.1f1 via code change, but behaving correctly if I manually edited the text value in inspector.

    In my case, it seems to be because the chain of code was flowing from a System.Timer Elapsed event call (text being updated every X milliseconds due to this event). For whatever reason, if the ultimate .text = "whatever" code executes from that approach, I can see it update in Inspector window, but the renderer (both scene and game view) do not update. Even tried called SetAllDirty() and Rebuild(), didn't change behavior. Never seen this kind of thing before.

    However, I refactored to use Unity's Update() method and a lightweight timer approach with Time.deltaTime (eliminating the use of a System.Timer), and now it works as expected (scene and game view both update rendering to what is in the .text value field in Inspector). Go figure.
     
  6. Zelre

    Zelre

    Joined:
    Dec 3, 2016
    Posts:
    55
    Having this exact same issue, also with 2018.3.1f1... I'm executing a change to my Text component when a button is clicked... I'm not using any Update functions as I'm displaying a gold value pulled through an external web database. Text value in the editor changes, but not on screen (unless I manually change something like Rich Text or anything in the component pretty much...)

    Please can you explain how you solved the problem in more detail?
     
  7. shtonz

    shtonz

    Joined:
    Oct 3, 2016
    Posts:
    1
    for me the problem was that the function that set the text field was not called from the main thread(it was a callback from Firebase retrieve data), the solution was to save the retrieved data in a private string and update the text field with this private string on the main thread(ex with the Update function), hope this helps.
     
    JumpWire likes this.
  8. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    469
  9. bluewiner

    bluewiner

    Joined:
    Nov 18, 2019
    Posts:
    1
    yeah I have the same issue with 2019.2.17f1. Same process like @shtonz mentioned. I am bringing data from firebase and set it to text.I couldn't understand how did you solved,could you explain again please?
     
unityunity