|Topic was automatically imported from the old Question2Answer platform.
Premise: I’m new to Godot.
I’m working on a 2D UI project, specifically an interactive slideshow. My aim is to make it responsive to different screen resolutions. I’m using GDScript to instantiate a scene that contains a Control node with an HBoxContainer. I dynamically add a row of themed buttons to the HBoxContainer using GDScript. The buttons retrieve their text from a dialogue manager, and their width can vary.
I want to arrange the buttons in multiple rows (HBoxContainers) if their total width exceeds the screen width. However, when I try to retrieve the size.x of the HBoxContainer or the buttons, it returns 0. Interestingly, I have a debug node that uses draw_rect to visualize the HBoxContainer, and it correctly displays the HBoxContainer’s size.
So, why isn’t the size available immediately upon instantiation? Is there a way to retrieve the size before rendering a frame?
as ld2studio suggested I’m using HFlowContainer now, graphically I have the result I was looking for without adding further HBoxContainer.
For the size 0 problem I added an
await get_tree().process_frame before using it (I tried
await instance.ready but it seems that everything after it is not executed, hanging forever?).
It seems to work as I expect and without glitches, it’s not clear to me why, I feel like I’m missing some fundamental piece of what happens between
instantiate() and the frame render.