+2 votes

I tried everyway I'v thought, and searched a long time here but without gook luck.
I just wanna change the Button, or Label, displaying font to a TTF, by scripts.
I tried these ways:

set("custom_fonts/font", load("res://FONT/mainmenu_button.ttf"))
add_font_override("custom_fonts/font",load("res://FONT/mainmenu_button.ttf"))
add_font_override("font",load("res://FONT/mainmenu_button.ttf"))
add_color_override("font_color", Color(1,0,0,1))
set("custom_fonts/font", load("res://FONT/mainmenu_button.ttf"))
set("custom_fonts/font", DynamicFont)
set("DynamicFontdata",load("res://FONT/mainmenu_button.ttf"))
set("font_data",load("res://FONT/mainmenu_button.ttf"))

The ttf font I wanna use is "res://FONT/mainmenu_button.ttf".
I just can't make it work.

Help me, plz.

in Engine by (21 points)

1 Answer

+3 votes
Best answer

Yeah completely undocumented, here is something that gets it done after some trial and error.

var path = "res://FONT/mainmenu_button.ttf" 
var new_font = DynamicFont.new()
var new_data = DynamicFontData.new()
new_data.font_path = path
new_font.font_data = new_data
set("custom_fonts/font", new_font)
by (997 points)
selected by

It works perfect!
Thank you very much!

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.