Updating label color

Godot Version

4,2

Question

Hi everyone! I’m trying to update a label font color as the game is running and the player collects stuff, i created a function on the ui scene:

func set_label_color(unit, color):
    if unit > 3:
        label.add_theme_color_override("font_color", color)

I then call this everytime the player collects anything on the game script by calling the function (with two variables on the main game scene:

func _on_baloon_body_entered(body):
   #more code
   ui.set_label_color(player.balloons, white)

I’ve tried several ways but none seem to work. the only help i could find online seemed to use the function add_color_override() which appears to be obsolete. Any clues?

2 Likes

Control.add_theme_color_override() should work as long as you don’t have a Label.label_settings resource which will take precedence over the theme.

Thanks for your response!
I don’t afaik. i just assigned the label to a variable (label) on the ui scene and the color to another to turn it white via function call (it’s set by default light yellow) within the main level scene

What renderer are you using ? I noticed in Compatibility, the font stays black.

You can do self["theme_override_colors/font_color"] = Color.BLACK or set("theme_override_colors/font_color", Color.BLACK)

2 Likes