Redraw on variable set (best way)

Godot Version

4.2.1

Question

In my project I often use custom UI. For this reason I often face a situation, when a class has a set of variables, and updating any of it should lead to redraw. For now I use code like following:

var show_controls: bool = true:
	set(value):
		show_controls = value
		queue_redraw()

var show_marking: bool = true:
	set(value):
		show_marking = value
		queue_redraw()

var curves: Array[Curve2D] = []:
	set(value):
		curves = value
		queue_redraw()

Obviously, this way leads to code duplication. Does there exist a more pretty way to achieve redraw queuing after a variable set?

This is the optimal way of doing it, if you look at it closely, the only repetition is fully unavoidable

1 Like