Godot 4.0 Change Progress bar Fill Color

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

How do I change a progress bar fill bg_color depending on the user life.

:bust_in_silhouette: Reply From: jgodfrey

Something like this should work:

  • Create a new StyleBoxFlat object
  • Assign it to ProgressBar fill style
  • Set the color of the stylebox as needed

So, in code:

func _ready():
	var sb = StyleBoxFlat.new()
	add_theme_stylebox_override("fill", sb)
	sb.bg_color = Color("ff0000")

Note, the above script is designed to be attached directly to the ProgressBar node. If that’s not your case, you just need a valid reference to it instead…

Once assigned, you can change the color as needed (just using something like that last line of code above).

1 Like