The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

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 (58 points)

1 Answer

+2 votes
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 (8,550 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 Frequently asked questions and 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 [email protected] with your username.