0 votes

I was wondering whether there is a way to set the font a char_fx uses in a RichTextEffect.
I cannot find anything about it in the documentation, but RichTextLabels can use [font=<path>] [/font], so I'm hoping custom effects can do the same.

I basically want to make that same effect, but through a custom RichTextEffect. I'd rather not have to write down the fontpath in each RichTextLabel, so I want to select a font through a name indicator. Writing down the paths in a single effect would make it easier to adjust them later (in case the path changes in the future), and would require less writing/path copying.

Here's what I have so far.

extends RichTextEffect

var bbcode = "f"

func _process_custom_fx(char_fx):

    var font

    match char_fx.env.get("name"):
        "font1": font = load("res://user interface/fonts/customfont1.tres")

    char_fx. ????

    return true

I'm wondering if there is a way to set the font property of the char_fx. Perhaps char_fx.font or char_fx.character.font

I essentially want to write [f name=font1] *text* [/f] to adjust the font of the text to font1

Godot version 3.2.3.stable
in Engine by (42 points)
edited by

1 Answer

0 votes

It's been a long time since you asked this. I'm sorry no one has answered you until now. I'm sure you have moved on since, but in case anyone else finds this...

This is not currently something you can accomplish within Godot 3.X. Perhaps in 4? I am unsure. For the time being you can set the font through BBCode, as you noted. I would recommend creating a function that wraps your code in a BBCode tag. Maybe something like:

func font1(text: String) -> String:
     return "[font=res://user interface/fonts/customfont1.tres]" + text + "[/font]"

Or, if you wanted something more dynamic you could do something like:

func set_font(text: String, font: String) -> String:
     return "[font=" + font + "]" + text + "[/font]"

This would let you pass in the text and the font path. Of course, you could expand on this function to allow you to pass in a name as your "font" variable and have the function set the right path.

Lots of options and maybe more to come in 4!

Happy coding!

by (22 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 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.