How to change the color of a word in the middle of a text

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

Example: “The sky is blue”
How to change the color of the word “blue”?

:bust_in_silhouette: Reply From: Eric Ellingson

Using a RichTextLabel, set bbcode_enabled to true, then bbcode_text you can do: The sky is [color=blue]blue[/color]

You can see a full list of colors here: BBCode in RichTextLabel — Godot Engine (3.1) documentation in English

:bust_in_silhouette: Reply From: Adam_S

With a RichTextLabel node you can use BBCode formatting.

First enable the “Bb Code” property in the inspector, then enter the code in the BBCode text field.

For your example the code would be: The sky is [color=#4ab3ff]blue
To stop using a color use [/color].

Note that you can simply test colors with the modulate property and copy the color code. Or just use one of the built in colors like [color=blue].

Of course you could do this also from script:

$RichTextLabel.bbcode_text = "The sky is [color=#4ab3ff]blue[/color]"

There is also a way to do this without BBCode, but I think this works only from script:

$RichTextLabel.add_text("The sky is ")

Thx alot dude, u solve my problems haha

DarlesLSF | 2019-09-26 10:44