Got bitten by shared resources in Godot UI this time. Every unit in my little prototype has a health bar scene, a ProgressBar with a StyleBoxFlat override for the fill. When health drops under 25 I wanted that one bar to go red, so I wrote this.
func _on_health_changed(value: float) -> void:
$Bar.value = value
var fill := $Bar.get_theme_stylebox("fill") as StyleBoxFlat
fill.bg_color = Color.RED if value < 25.0 else Color.GREEN
First unit takes a hit and every bar on screen turns red. The override was a sub-resource saved inside the bar scene, and every instance of the scene got the very same StyleBoxFlat object. Set a property on it and it's set for all of them. Obvious once you see it, it's one object.
What I'm unsure about is the fix. Call duplicate() in _ready, tick resource_local_to_scene, or stop writing to the stylebox at all?
