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