Godot 4: Font size does not change when set by code.

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

Hello,

I’m making a responsive game in which I want the font sizes to be changed depending on the user’s screen size, but it does not work when I try to change it by code using “Control.add_theme_font_size_override()” or “Control.add_theme_constant_override()” with the same arguments. I’ve also tried removing some posible “default” constant override with the same name that maybe was existing there before, but neither worked. Here’s how I reproduced it:

var font_size : int = int(settings.resolution.x * 0.35)
play_button_label.add_theme_font_size_override("theme_override_font_sizes/font_size", font_size)

Thanks in advance!

:bust_in_silhouette: Reply From: Leon12

SOLUTION: change the “name” argument to “font_size”, like this:

play_button_label.add_theme_font_size_override("font_size", font_size)
1 Like