how do you change the font text color in a label from code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alienbeliever
:warning: Old Version Published before Godot 3 was released.
:bust_in_silhouette: Reply From: volzhs

get_node("Label").add_color_override("font_color", Color(1,0,0,1))

:bust_in_silhouette: Reply From: rayosdev

Example

set("custom_colors/font_color",Color(1,0,0))

any parameter that doesn’t have a direct getter or setter method can be accessed through
get(-the path hint you get when mousing over any parameter-)
e.g "custom_colors/font_color"

get() also needs a second parameter witch is what you want to change
e.g Color(1,0,0)

Can you change a property of the color directly? e.g. the alpha? If so, how?

vetu11 | 2020-09-30 12:15

:bust_in_silhouette: Reply From: RadianDRZ

get_node("Label").set("custom_colors/default_color", Color(1,1,1,1))

The above would be white text.

Thanks, this was very helpful. I assume things have been updated since 2017 as none of the other answers worked!

jamesgiddings | 2021-01-13 13:39

Thanks. It’s a bit of trial and error sometimes. I’ll try to contribute as much as I can. All the best!

RadianDRZ | 2021-01-14 23:39

:bust_in_silhouette: Reply From: gamedevshirious

I was able to change font color with modulate property.

lbl.modulate =  Color(1, 0, 1)

I guess this works, but if the font color of the label isn’t white, then the new color won’t be the exact color displayed.

exuin | 2021-04-19 19:50

:bust_in_silhouette: Reply From: Gatada

For Godot 4 the property path has changed.

$YourLabel.set("theme_override_colors/font_color", Color(1, 0, 0))

However, the approach I used to find this answer might also be helpful:

  1. Find the property you want to set in the editor node Inspector.
  2. Right-click the property label and select Copy Property Path.
  3. Set the property on your node using the copied path: <node>.set("<path>", <value>).

The challenge to understand which property to set remains. For example, I did not see the set color on my label because the Label Settings was set.

:bust_in_silhouette: Reply From: gemmomoh

In Godot 4

$Label.label_settings.font_color = Color.DARK_RED