Tweening a Label's Text Color

Godot Version

4.2.2

Question

I understand how to change a Label’s text color (using set()), but I can’t seem to find out how to tween its color. There seems to be no documentation on how to do so and I don’t think set() allows you to tween. Is there a way to do this?

Nothing really specific about tweening a property here, pretty standard stuff:

tween.tween_property(self, "theme_override_colors/font_color", Color(1, 1, 1, 1), 5)

(edit: this will change the colour to white over 5 seconds)

You could also tween modulate too. Property names can be found in the Inspector tooltips (can also copy them from here too, paste into code).

2 Likes

Use Tween.tween_method().

# Your function to tween should accept a parameter that the tween will tween through.
create_tween().tween_method(function_to_tween, from_color, to_color, duration)

You can create a function such as:

func function_to_tween(color: Color) -> void:
    my_label.add_theme_color_override("font_color", color)
1 Like

Wow, that makes a whole lot more sense. I did actually try that before, but I wasn’t using theme overrides correctly in the first place (I didn’t have it enabled). Thanks for clarifying, though!

1 Like

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