How do I get the global position of 'Button's children of Control Nodes?

Godot Version

4.4

Question

I’m sorry if my English is confusing

I have the following structure of nodes, and I need to get the individual position of each button, I’ll draw a line through these buttons:

Control/CanvasLayer/Panel/VBoxContainer/Control/Panel/HBoxContainer/VBoxContainer/Button

var node = Button
# It's inside a loop, would be very extensive the entire code

var point_a = node.global_position
print(point_a)

The point is: the global_position or any other methods I’ve been trying these days, always return (0.0, 0.0), or the same coordinate (that I calculated as being the top-left of the first Panel)

Any other methods I could try?

Here are some stuff I tried and failed completely:

var point_a = node.??

?? would be:
{
    global_position
    position
    get_global.position()
    rect_position
    get_parent().get_node(node.name).rect_position
    get_local_position()
}

is your CanvasLayer expanded to the whole screen?

1 Like

Do you access the global position in _ready? In that case the position is not yet finalized and you would need to wait one frame until the position is available.

1 Like

@thomas Yep


Yes, I called the entire function using:

await get_tree().create_timer(0.0).timeout
_update_node_mesh()

_update_node_mesh() is my problematic function.

Actually, the output of the coordinates are a Vector2, and the Vector2.x is correctly being printed, but the Vector2.y is the same in every Button.

Thank you, your answer really helped me a lot, but the Y vector is still buggy.

My Hypothesis:

Because I have a HBoxContainer and multiple VBoxContainers, the VBoxes are set correctly, but the Buttons not yet, but two awaits weren’t useful.

Edit:

ANSWER

Thank you, @Sauermann , you helped me a lot. I tried to place another await, after the dynamic VBoxes and before the coordenates, and that worked perfectly.

Kind Regards,
NicolasB