Canvas UI Text - Not Updating (Unity 2019.1.0f2)

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.

2 Likes

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.

1 Like

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

2 Likes

You are affected by a bug know by unity :

https://issuetracker.unity3d.com/is…d-via-script-when-image-type-is-set-to-simple

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.

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?

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.

5 Likes

@LeonhardP I can confirm that this issue is not fixed on latest 2019.3.0b11. According to Issue Tracker it is, but from the comments it seems others also still have the same issue. Unity Issue Tracker - Image Color cannot be changed via script when Image type is set to Simple

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?

1 Like

i have this issue still in Unity 2019.4.5f1 (64-bit) -
any ideas?

Can you please report a bug if you can reproduce?

I am having the same issue as well when trying to change via code. Unity 2019.4.5f1 …

it wasn’t a bug in unity, i’ve made a mistake updating the text values.
It even worked in 2018, no reproduction

1 Like

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.

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.

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

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.

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.

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/reference/unity/class/firebase/extensions/task-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 :slight_smile:

4 Likes

This fixed it for me. Why would Firebase suggest ContinueWith on their docs?

1 Like