Set `char_fx`s Font in RichTextEffect

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

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

:bust_in_silhouette: Reply From: ASubtleIncline

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!