I am using a scrollcontainer with one vbox child. The vbox child has multiple label nodes.
This is what the tree looks like,
- ScrollContainer (
follow_focus
property is set)
- VBoxContainer
- Label1 (added at runtime)
- Label2 (added at runtime)
- Label3 (added at runtime)
Here is a link to a small scene illustrating the problem:
When I add Label3
to the tree, I expect the scrollcontainer to scroll to the bottom.
But the behavior is very random. Sometimes it scrolls to the bottom, sometimes it doesn't.
This is the code I have,
func create_label_with_message(message: String):
var lbl: Label = Label.new()
lbl.text = message
lbl.autowrap_mode = TextServer.AUTOWRAP_WORD
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
lbl.focus_mode = Control.FOCUS_ALL
add_child(lbl)
await get_tree().process_frame
scroll_container.ensure_control_visible(lbl) # (mentioned in the docs for Scrollcontainer)
After 3 hours of banging my head against the wall, the following magical incantation works,
func create_label_with_message(message: String):
var lbl: Label = Label.new()
lbl.text = message
lbl.autowrap_mode = TextServer.AUTOWRAP_WORD
lbl.mouse_filter = Control.MOUSE_FILTER_IGNORE
lbl.focus_mode = Control.FOCUS_ALL
add_child(lbl)
await get_tree().process_frame
await get_tree().process_frame # (this is the only extra line added)
scroll_container.ensure_control_visible(lbl) # (mentioned in the docs for Scrollcontainer)
The only thing I changed was I added await get_tree().process_frame
twice.
Can someone please tell me what might be going on?
I'm trying to understand why adding the line await get_tree().process_frame
twice makes it work.
I am trying to convince my boss at work to use godot for an internal project.
And this makes me wonder what other hidden "gotchas" there are.