change theme font via gdscript

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

I want to change theme font via gsdcript, on a script that is not atached to any control node.

:bust_in_silhouette: Reply From: rossunger

That sounds like an anti-pattern… Which theme are you trying to change? The default one?

Normally you would use get_theme().set_font(etc...) but if it’s not a control, then you can’t do that … I guess you could do Control.new().get_theme().set_font()
Or you could do var myTheme = preload("path to your theme) and go from there

The theme i am trying to change is mine in a node script, my current code is this now, but didn’t work.
func toggle_dyslexic_friendly_font(value): var mytheme = preload("res://user_interface/default_theme.tres") var font = load("res://user_interface/fonts/open_dyslexic_dynamicfont.tres") Control.new().get_theme().set_default_font(font)

VinicOliver8394 | 2022-02-16 17:31

Replace the last line with myTheme.set_default_font(font)
Although, you probably need to save the theme too… Depends on how you plan to use it next?

If that doesn’t work, you might need to instance the theme too (I haven’t tried this with themes specifically… Might need do preload(…).instance() or preload(…).new() … I don’t think you need to do that, but you might

rossunger | 2022-02-16 17:39

Also, if youre trying to change the default project font, there’s a project setting for that! custom_font

rossunger | 2022-02-16 17:40