This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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.

Godot version 4.0.3
in Engine by (12 points)
edited by

Phew, it's such a relief to say that after a considerable amount of time and effort, I have, at long last, come up with a viable solution.

You should post the solution lol

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.