Setting Label Text Overwrites Global Position

Godot Version



I’m having a strange issue with changing the text and global_position of a label via code. I think this may be a bug, but I’m new to godot so I’ll describe the steps to reproduce below. The crux of the issue is that when I change the text value of a label with Anchors Preset: Center Top and then set the global_position.x to some other value, it takes one whole process frame for the global_position.x to have the desired value. There is some intermediate value that overwrites the value in the same process frame in which the label text was changed.

Steps to Reproduce

In a project with a single scene (Main.tscn), there is a single Label (nothing else) with default text “Hello” and Anchors Preset set to Center Top. Below shows the code inside of the script:

extends Node2D

@onready var label = $Label

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	label.text = "Goodbye"
	print("BEFORE - label.global_position: " + str(label.global_position))
	label.global_position.x = 100
	label.global_position.y = 100
	print("AFTER - label.global_position: " + str(label.global_position))

Console Output (stopped after 2 process frames):

BEFORE - label.global_position: (-24, 0)
AFTER - label.global_position: (90, 100)
BEFORE - label.global_position: (90, 100)
AFTER - label.global_position: (100, 100)

I am expecting the value of the label.global_position.x to be 100 when I print it after setting the value, but you can see that is not the case. Instead, it prints a value of 90. I have isolated the issue to happening when the Anchors Preset is set to Center Top on the label and when the label text gets changed in the same process frame that you attempt to change the global_position.x in.

Any guidance or help is much appreciated.