0 votes

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

Godot version 3.2.2
in Engine by (17 points)

1 Answer

+1 vote
Best answer


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.

by (7,190 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.