Get accurate position of instanced control scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Thewolfs

Hi,

I’m relatively new to Godot and trying to create a Skill Tree GUI with custom buttons. I manage to dynamically add all my nodes but the issue comes when I want to draw lines between the parent node and the children nodes. I’ve tried to get the positions from the child nodes relative to the current scene by any way I can but the xOffset is way off :

Here is how my scene look likes when rendered (in blue what I want to draw) :

Here is what the console prints out :

Skill1Button Children : (10, 120, 1920, 0)
Skill2Button : (10, 120, 1920, 115)
Skill2Button Children : (10, 235, 1920, 0)
Skill3Button : (10, 120, 1920, 115)
Skill3Button Children : (10, 235, 1920, 0)
Skill4Button : (10, 235, 1920, 115)
Skill4Button Children : (10, 350, 1920, 0)
Skill5Button : (10, 235, 1920, 115)
Skill5Button Children : (10, 350, 1920, 0)

Skill2 and 3 are children of Skill1 and Skill4 and 5 are children of Skill3

Here is the code of the function getting the rects (I get the same result with get_global_position() ):

func update_visual_links() -> void:
var children = $Children.get_children()
print(get_name(), " Children : ", $Children.get_global_rect())
for child in children:
	print(child.get_name()," : ", child.get_global_rect())
	child.update_visual_links()

Here is a picture of my Button Scene :

Thanks in advance for your help, I’ve been stuck on this for hours

I dunno but try to use rect_global_position and rect_size instead.

Dlean Jeans | 2019-06-16 02:35

Already tried, had the same results

Thewolfs | 2019-06-16 03:45

What the bounding box around your buttons look like? Seems like they’re messed up or something.

Dlean Jeans | 2019-06-16 06:37

Here’s a picture with the ResearchTreeButtonContainer, ResearchTreeButton and Children :

Thewolfs | 2019-06-16 08:00