Search Unity

Canvas UI Text - Not Updating (Unity 2019.1.0f2)

Discussion in 'UGUI & TextMesh Pro' started by Plumpman, Apr 18, 2019.

  1. Plumpman

    Plumpman

    Joined:
    Sep 7, 2012
    Posts:
    27
    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
    Seiderlord and mimiCryMuffin like this.
  2. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    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.
     
    mimiCryMuffin 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
     
    anis_loum and BennettDeveloper like this.
  4. roka

    roka

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

    sampenguin

    Joined:
    Feb 1, 2011
    Posts:
    64
    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.
     
  8. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
  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?
     
    gooby429 likes this.
  10. wolfomat

    wolfomat

    Joined:
    Oct 19, 2014
    Posts:
    24
    i have this issue still in Unity 2019.4.5f1 (64-bit) -
    any ideas?
     
  11. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Can you please report a bug if you can reproduce?
     
  12. Rio_TFF

    Rio_TFF

    Joined:
    Aug 4, 2019
    Posts:
    21
    I am having the same issue as well when trying to change via code. Unity 2019.4.5f1 ...
     
  13. wolfomat

    wolfomat

    Joined:
    Oct 19, 2014
    Posts:
    24
    it wasn't a bug in unity, i've made a mistake updating the text values.
    It even worked in 2018, no reproduction
     
    fherbst likes this.
  14. stenfeio

    stenfeio

    Joined:
    Jan 18, 2015
    Posts:
    22
    Issue remains in 2019.3.4f1. Setting a text component's text variable does not update the first time around. For some reason, the text is filled with some other variable close by (in memory). Seems like data corruption. Fix for this is to set the visibility of the Text ui component,
    yield return null
    for one frame and then update the text. This means your method needs to run as a coroutine for this to work. Annoying working around but it works.
     
  15. fhecorrea

    fhecorrea

    Joined:
    Aug 30, 2019
    Posts:
    1
    Same problem. What it happens to @shtonz and @bluewiner, it's happening to me. My Unity version is 2019.4.4f1 downloaded via Unity Hub.
    OS: Linux.
    Platform: Android.

    Sorry for this thread ress.
     
  16. oigetinthevan

    oigetinthevan

    Joined:
    Aug 1, 2018
    Posts:
    6
    Ok, so, similar symptoms, but a potentially different problem to those above.

    Spent the last 30 minutes investigating why UI text elements weren't updating. Code was sound and everything in the Inspector was hooked up just fine, but UI still wouldn't update.

    Restart Unity. Problem solved.

    I really hate computers sometimes.

    Unity 2020.1.7f1
     
  17. darkwepsupp

    darkwepsupp

    Joined:
    Dec 24, 2020
    Posts:
    1
    Same problem on 2020.1.16f1
    I spent like a week on this problem, I was sure it was my fault, because there is no logic that can describe the reason of this problem.
     
  18. unity_7goiPoUnrRyJvQ

    unity_7goiPoUnrRyJvQ

    Joined:
    Jan 11, 2021
    Posts:
    1
    I have exactly the same issue...the exact same code worked a night before and now it stopped working in Unity 2020.1.7f1 with text fields not updating anymore. Will try to update the Unity version.
     
  19. gooby429

    gooby429

    Joined:
    Aug 13, 2019
    Posts:
    136
    I was having the same annoying issue for a week. The issue is that the tasks you are running are being run on a separate thread, which is how async tasks work, especially with firebase. You have to join it to the main thread first by using the extension method
    ContinueWithOnMainThread
    instead of
    ContinueWith
    (make sure to declare
    using Firebase.Extensions;
    at the top). More info: https://firebase.google.com/docs/re...-extension#continuewithonmainthread-tresult_1

    I think this applies to most of the issues in this thread since it appears everyone is trying to set the UI asynchronously, which does not work since Unity runs everything on the main thread. Hope this helps someone else :)
     
  20. icyku

    icyku

    Joined:
    Aug 7, 2014
    Posts:
    2
    This fixed it for me. Why would Firebase suggest ContinueWith on their docs?
     
    efsiprocanik likes this.
  21. gooby429

    gooby429

    Joined:
    Aug 13, 2019
    Posts:
    136
    Bc for all intents and purposes it works fine and firebase is not totally associated with unity i suppose? Also, their docs aren't great so we might just need to suggest they add it
     
  22. therealgeraldsy

    therealgeraldsy

    Joined:
    Mar 6, 2019
    Posts:
    1
    This worked for me, so what I did is

    1. declared a string variable at the start "string userVal"
    2. on my function that doesn't update the text value on the GUI, I did this "userVal = "value of the string I wanted to put"
    3. on void Update() function, I did this "usertext.text = userVal;"
    4. the usertext variable is a "public TMP_Text usertext;" declaration where it is the Text TMP I used in the GUI

    I hope it is clear hehe
     
  23. dyguests

    dyguests

    Joined:
    May 4, 2015
    Posts:
    16
    I think I got the reason.
    It happens to me too.

    I used UniRx package.

    When I update text in Observable.Start(...),the text not udpated, and it seems interruptted but none exception shown in Console.
    When I update text in Observable.FromCoroutine, it works fine.


    Too see UniRx source:
    Code (CSharp):
    1.  
    2.         public static IObservable<T> Start<T>(Func<T> function)
    3.         {
    4.             return new StartObservable<T>(function, null, Scheduler.DefaultSchedulers.AsyncConversions;
    5.         }
    6.  
    It seems we can only update text in main thread?(or canvas not update, etc.)

    Anyway, I fixed it by use Observable.FromCoroutine instead of Observable.Start.
     
  24. ShadowlessStudios

    ShadowlessStudios

    Joined:
    Jan 8, 2017
    Posts:
    16

    You Saved my Life with the suggestion of makeing it
    ContinueWithOnMainThread
    instead of
    ContinueWith
    . I had this problem for years but never try to really fix it until yesterday. It cost me nearly 1 day without any solution. I made so many workaorunds to solve it in any way without fixing it. Finnaly i testes what you said. And tata it works. Thank you sooo much really man :)
     
    gooby429 likes this.