Label text doesn't update displayed value, but property content correctly changes

Godot Version

4.2.2.stable

Question

Hi, the code is very simple.

func _on_do_things_button_pressed() -> void:
	label.text = "String one"
	function_that_does_things()
	label.text = "String two"

I have a Main node that receives a signal from a button when pressed, and triggers the function _on_do_things_button_pressed (all local, no network calls involved).

Stepping through the code with the debugger, I see that the string “String one” is correctly set (the label content property changes) but the displayed value doesn’t. When it reaches the point where it sets the “String two”, in this case the string is correctly displayed.

Why isn’t displaying the “String one” value?
Thanks for your help.

You are changing the text property twice in the same frame. The Label will only render at the end of the frame so it won’t render the first change.

Yes, that’s the problem. I was in a hurry so I also asked in the discord and a user guided me to the resolution, that involved adding two await get_tree().process_frame after the label.text = "String one" assignment.
The same user also suggested to use threads, but I didn’t dived deeper.

By the way, can you point to some relevant documentation/resource to better understand the handling of the frames that Godot does?

Thanks.

I’m not sure if there’s something in the documentation specifically explaining that. You could check the Getting Started section in the documentation where it may give you more info about that.