• Godot Help
  • changing font size of the label through code

Currently if I want to change the text size of the label I do the following:

        var label = GetNode<Label>("Text");
        label.AddThemeFontSizeOverride("font_size", 24);

I would like to change the code to a more dynamic way, like so:

        label.Set("theme_overrides/font_sizes/font_size", 24);

does the font size modifications support this kind of property update syntax?

here is what the targeted property looks like in the editor:

I figured that "theme_overrides/font_sizes/font_size" would be the correct path but it's not.. How do I properly discover the path of a property?

    dearme p.s. none of the following work 🙂

            label.Set("theme_overrides/font_sizes/font_size", TextSize);
            label.Set("theme_overrides/font_sizes:font_size", TextSize);
            label.Set("theme_overrides/font_size", TextSize);
            label.Set("font_size", TextSize);
            label.Set("theme_overrides:font_sizes:font_size", TextSize);
            label.Set("theme_overrides:font_size", TextSize);
            label.Set("theme_overrides/:font_sizes/:font_size", TextSize);
            label.Set("/theme_overrides/:font_sizes/:font_size", TextSize);
            label.Set("theme_overrides:font_sizes/font_size", TextSize);
    6 months later

    Did you ever figure it out? I've been trying to change my label size using this.

    Note, does not work
    @onready var label_fs = $HBoxContainer/VBoxContainer/Label_fs

    label_fs.theme_override_font_sizes/font_size() = 60

    Update/Edit: These 2 code works for Godot 4.1.2, (documentation explanation lacks proper explanation)

    Font Size change via GD Script [in Godot 4.1.2]:
    label_fs.add_theme_font_size_override("font_size", 32)

    For changing font via GD Script [In Godot 4.1.2]:
    label_fs.add_theme_font_override("font", load("res://assets/24LedBright.ttf"))