How to set 2D node’s transformation origin to its center?

Godot Version

4.6

Question

Hello,

I am currently implementing a 2D HUD system in my 3D game.

The issue is that when I manage the 2D position of a “Label” node (for example) via GDScript the element is positioned relative to its parent (a Control node) using its top-left corner as the origin instead of its center. Consequently, I have to consistently offset the element by half of its dimensions or parents it to an empty node. And nothing happens when I define the pivot offset to vector2(0.5, O.5) in the inspector.

Do you know a way to set a 2D node’s transformation origin to its center rather than its top-left corner?

Thank you in advance for your answers and have a nice day.

There’s no setting for this, Control nodes always position from their top left. That’s baked into how Controls work.

Two notes on what you tried: pivot_offset is in pixels, not a 0 to 1 ratio, so (0.5, 0.5) is half a pixel. And it only affects rotation and scale, never position, which is why nothing seemed to happen.

For placing by center, the usual way is exactly the offset you’re already doing: label.position = target_pos - label.size / 2. If you want it tidy, wrap it in a one line helper or a small script with a set_center(pos) function and the offsetting stays in one place.