Trying to make the highlight of a RichTextLabel blink

Godot Version

v4.2.stable.official [46dc27791]
Godot v4.2.stable - macOS 14.2.0 - Vulkan (Forward+) - integrated Apple M1 - Apple M1 (8 Threads)

Question

I’m using a RichTextLabel for dialogue system in my project. One part of the message is using a highlight, that is, the area behind text is filled with solid color.

How can I make this highlight blink? Not the text itself, only the highlight.

1 Like

Hi! If I was doing this, I would create a custom text effect for the bbcode
https://docs.godotengine.org/en/stable/tutorials/ui/bbcode_in_richtextlabel.html#custom-bbcode-tags-and-text-effects

However, looking at the CharFXTransform class documentation, it doesn’t look like you can access background colour of a character and change this. Maybe you could directly draw onto it? Or use an outline effect instead?

Yes, I can’t access the “highlight” property, this is the problem. “Outline” etc are all accessible but “highlight” isn’t.

I tried making custom effects, but didn’t manage to make it work. Unofficial instructions (there are some on youtube and so on) all deal with Godot 3, and official Help is not going into details that are necessary for making it work.

For example, if I want to install the custom effects from code instead of assigning it in the Inspector, the instructions just say something like: just install it, it’s very practical! I’m supposed to do it like this:
image
Where does this code go? In “ready” of the RichTextLabel? I tried everything I can think of but just can’t make it work.

The highlight (background color/bgcolor) isn’t part of the text itself, but is drawn as a rectangle by RichTextLabel itself. I don’t think there’s a way to access it from RichTextEffect, so you have to create a custom RichTextEffect that replicates bgcolor’s functionality while making it blink.

Reading the source code implementation, you should be able to call _install_effect(preload("res://path/to/custom_effect.gd")) in a RichTextLabel script’s _ready() function.

1 Like

[quote=“Calinou, post:4, topic:38042”]
Reading the source code implementation, you should be able to call _install_effect(preload("res://path/to/custom_effect.gd")) in a RichTextLabel script’s _ready() function.[/quote]

Thank you for looking into this, I really appreciate it!

I tried adding the code from your example by copy pasting it (and adjusting the file path), it doesn’t work because it has an underscore. So I tried other variations. None of these worked:


(using the “ghost” effect from the official Help)
I tried all other variations I could think of too but forgot to screenshot it.

And just to confirm, this works fine when I add the custom effect in the Inspector (I can see the individual letters fading in and out).

(sorry had to separate this into two posts because the forum doesn’t allow new users to post more than one multimedia something per post)
But even adding it in the Inspector is a bit confusing. While adding it to the array of effects, if I use QuickLoad it doesn’t show up at all. Where is it? So I have to select it from the menu and then it works. Here is a screen capture showing it in action:
Godot where is the bbcode

ok I found it, it’s
install_effect(RichTextGhost.new())
How was I supposed to know this :stuck_out_tongue:

I’ve opened a PR to improve documentation on this: Improve RichTextLabel `install_effect()` documentation by Calinou · Pull Request #86331 · godotengine/godot · GitHub

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.