+1 vote

I'm looking for a way to change the default font of a theme by code. This would be used to implement font scaling depending on the window size.

I've found how to change the custom font of a label already:

get_node("MyLabel").set("custom_fonts/font", my_font_data)
in Engine by (10,259 points)

1 Answer

+1 vote

You can do something like this:

var theme = get_theme()
var newfont = load('assets/fonts/different-font.fnt')
theme.set_default_font(newfont)

I haven't confirmed whether this works on controls that just inherit a theme; if it doesn't, just call get_theme() on the themed parent control instead.

(Also, if all you're changing is the size, you can probably refine this to use DynamicFont and DynamicFontData.)

by (332 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 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 webmaster@godotengine.org with your username.