Texture buttons and their pivot points aren't centered when I add them to the scene.

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

Why are the texturebuttons I place into the scene are way off center to the bottom right from the mouse position that is given to them using set_position(). Their pivot points when resizing them also seem to be at their top left which is seen when their size changes on mouse hover.
When i was using sprites instead of texturebuttons, this issue wasn’t prevalent.

Godot, off center texture buttons image

Any suggestions would be much appreciated!

:bust_in_silhouette: Reply From: kidscancode

Have a look at the Control’s rect properties. “Grow Direction” determines in which direction(s) the object grows when resizing - you probably want “Both”. You can also set the “Pivot Offset” to the center of the Control rather than the default of (0, 0) (top-left corner).

#hopefully this fixes the offset issues
	rect_pivot_offset.x = .5
	rect_pivot_offset.y = .5

put this under _ready(), It didn’t change anything unfortunately (also tried a bunch of random values and no difference.).

i also tried (with and without the pivot_offsets)

grow_horizontal = Control.GROW_DIRECTION_BOTH
grow_vertical = Control.GROW_DIRECTION_BOTH

under _ready() and the icons are placed to the far top right and no longer open up with my script which moves the icons. (the icons still grow in the same direction on hover btw)
:confused: i could try to recreate a more basic example that focuses on this issue to demonstrate it but yeah. I’m starting to think this is a problem with how these buttons were implemented.

(i drew where my mouse is relative to the icons (bottom left))
mouse distance

I might just have to create a sprite and child the texture button to it for this to work properly.

KnightNine | 2019-07-21 04:50

:bust_in_silhouette: Reply From: KnightNine

update for reference:

The issue was that Godot doesn’t give you control of the pivot offset (and probably other controls) through the code of nodes I created and set the values for dynamically from the scene itself. I had to make a separate scene to create instances of these buttons from; where all these settings are already applied to an existing button.

Guess that Godot isn’t built for certain more complex nodes like textureButtons to be created dynamically. If Godot had thrown an error instead of allowing me to create these nodes dynamically in the first place, i would’ve figured that wasn’t the way I was meant to do this sooner.