Pivot Offset not affecting Label scaling

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

I have a VBoxContainer to which I add Labels in code. I then set the pivot offset of the labels to their centers:

        for i in range(num_selections):
            new_selection = Label.new()
		    new_selection.name = "Selection" + str(i)
			new_selection.text = selection_texts[i]
			new_selection.align = Label.ALIGN_CENTER
			selection_box.add_child(new_selection)
			new_selection.rect_pivot_offset.x = new_selection.rect_size.x/2
			new_selection.rect_pivot_offset.y = new_selection.rect_size.y/2

Later in code when I scale the Labels the scale behaviour seems to be ignoring the pivot offset and stretching the Label up and to the right.

Is this a consequence of the label being a child of a VBoxContainer? Is there some way to force the label to scale in the way I want?

:bust_in_silhouette: Reply From: timothybrentwood

If your VBoxContainer isn’t already a child of something in the scene

 new_selection.rect_pivot_offset.x = new_selection.rect_size.x/2
 new_selection.rect_pivot_offset.y = new_selection.rect_size.y/2

will both be set to 0 and the labels will be stretched down and right by default. If they’re being stretched up and right… something strange is going on. Make sure your VBoxContainer is added to a node in the scene before adding your labels to the container and see if that fixes your problem.

Have you used the remote inspector to see what the values of your labels’ rect_pivot_offset s are at runtime?