+7 votes

If I'm not wrong, add_child adds a node in the last position of his parent. There's an additional function add_child_below_node that allows adding a node after to another specific one, so you can add a node in index 1, index 2, index 3, etc.. but never as first one.

  1. Am I right?

  2. How can I add a node at index zero, then?

  3. Why there's no function for adding at specific index? Or at least for adding above node so we can use it to add as first node. Maybe I should add an issue on this, but I'm surprised there's no way to do such a simple thing and maybe there's a reason for it (couldn't find it tho)


in Engine by (120 points)

In my case I want to do this for adding elements to a HBoxContainer in specific positions and could use a fixed empty node as first child as a workaround.

1 Answer

+17 votes
Best answer

after `add_child()

move_child(child_ref, 0)
by (408 points)
selected by

Thanks! That answers my first two questions and makes the third one pretty irrelevant.

glad to help :)

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.