I’ve got a VBoxContainer that contains text elements, and is of variable height. I would like to be able to know the height when I add it to the tree, so I can position it. (The control itself is not the child of another container, I want to position it arbitrarily.)

The workaround is to await get_tree().process_frame so I can get its size (after it goes through the control layout process). I’ve seen suggestions to use container.notification(Container.NOTIFICATION_SORT_CHILDREN) but this doesn’t update the height of the children (which are Label or RichTextLabel).

Is there a way to do a hypothetical box.perform_all_layout() instead? (In Unity I used LayoutRebuilder.ForceRebuildLayoutImmediate for something similar.)

In the case of an element whose size depends on its contents, I don't think you can determine the size until it's visible. But you can set the alpha channel of its modulate property to zero to make it transparent, if you want it to keep it hidden temporarily.

Yes, I think I’ve done that on occasion. It still means there’s a one frame delay before you can accurately position the container (though it can help prevent visual glitches).

why dont you use maths? You are adding text elements at known height so you can calculate the height given that you know the margins etc.. no?

Why would text be known height? This is arbitrary text from a narrative game, which could be multiple lines when wrapped. Label and RichTextLabel are going to be the best tools to do the measurement. If I could only get them to do the measurement now and not at the end of the frame.

    radiofreelunch maybe you are waiting for the text processing? idk, what if you try to set the rtl to threaded and await for the text to be processed after you add text to it, and then add it to the container or read the height value?

    https://docs.godotengine.org/en/stable/classes/class_richtextlabel.html#class-richtextlabel-property-threaded

    https://docs.godotengine.org/en/stable/classes/class_richtextlabel.html#class-richtextlabel-method-is-finished

    Interesting idea. I think that doesn’t help because I still need to await — in practice most of the text is one line or two lines (and the VBoxContainer holds two or three of them so I might need to block on three threads).

    Pretty sure I haven’t gotten an answer for how to measure/layout without await because it simply isn’t possible yet.

      radiofreelunch well the beauty of opensource, is that you can "fix" the source yourself 😃...

      I tried to read through the source but i didnt like the language and all the header declarations that lead to nowhere ... Maybe there are some commits floating around the hub that you could add to your fork that fixes what you asking for?

      But i feel your pain, sometimes what you want the "maintainers" dont see the importance of that so they never try to look at fixing/implementing