How to set font data for a label via gdscript?

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

The label was created with gdscript, and I need to set its font data via gdscript. How do I do this?

What do you mean by “Font Data”? Are you asking if you can edit how the font looks with script? Because you could just download a font from the internet (I recommend [https://www.dafont.com/] [1] as it is widley used and trusted by game developers and media producers alike) or create one yourself with many programs which are available online.

Amateur.game.dev. | 2020-09-12 12:54

No, I already have the font data downloaded. What I need to do is to assign it to the attribute in the label node, and I’m not sure how to do that via code.

exuin | 2020-09-12 18:51

:bust_in_silhouette: Reply From: njamster
func _ready():
    var dynamic_font = DynamicFont.new()
    dynamic_font.font_data = load("<Path To Font-File>")
    $Label.add_font_override("font", dynamic_font)

Thanks, it worked!

exuin | 2020-09-14 02:38