How to make HBox spacing depend on the number of children?

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

Is it possible to make the HBox spacing depend on the number of children? I want to make a heart hud and I want to reduce the spacing between hearts as their number increases.
Like this
3 hearts, big spacing
many hearts, small spacing

:bust_in_silhouette: Reply From: exuin

Yes.

func _ready():
    separation = some_variable / get_child_count()

And every time the number of hearts changes, just recalculate the separation. If you want this to appear in the editor as well, you’ll need a tool script. See this and this.

Oh, yeah, this makes sense, I can just recalculate separation from code whenever I add more hearts. Thanks!

sunDalik | 2021-04-16 18:32