0 votes

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

Godot version 3.4.2
in Engine by (33 points)

1 Answer

+1 vote
Best answer

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

by (1,292 points)
selected by

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)

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

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

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.