0 votes

I'll boil this problem down to the minimum:


extends Node2D

export (Font) var label_font setget _set_label_font
export (String) var label_text setget _set_label_text
var label_size
var ready = false

func _ready():
    ready = true

func _process(delta):

func _set_label_font(value):
    label_font = value
    if ready and value != null:
        $Label.add_font_override("font", label_font)

func _set_label_text(value):
    label_text = value
    if ready:

The tool has a label as its child. Whyyy has the label not updatet it's rectangle at the END of _ready(), but at the first value that _process(delta) prints. I have trouble understanding this and it ruins my code.

in Engine by (842 points)

2 Answers

0 votes

Solved. Seems like you have to update the position of it to be having the rect_size updating aswell.

by (842 points)
0 votes

for performance reason,
some of properties are not updated immediately.

extends Label

func _ready():
    text = "test string"
    printt("size =", rect_size) # (40,14)

it's just default size of Label

you can get the actual size of Label in several ways.

Wait for 1 frame

extends Label

func _ready():
    text = "test string"
    yield(get_tree(), "idle_frame")
    printt("size =", rect_size) # (65, 14)

Force to get size

extends Label

func _ready():
    text = "test string"
    printt("size =", get_combined_minimum_size())  # (65, 14)

Get size with signal

extends Label

func _ready():
    connect("item_rect_changed", self, "on_item_rect_changed")
    text = "test string"

func on_item_rect_changed():
    printt("size =", rect_size) # (65,14)
by (9,776 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.