IssueRaiser

Add a `Node.add_child_at()` method to add a node at a specific index

**Describe the problem or limitation you are having in your project:** There is currently no way to directly add a child at an arbitrary index. The options we are have are either: 1. `add_child` then move it with `move_child` 2. Use `add_child_below_node` to specifiy a sibling. This method is already pretty poor and [has been replaced](https://github.com/godotengine/godot/issues/19642) with `add_sibling` in `master`, and it doesn't allow you to add a node at index 0 because the new node is added after the sibling. Honestly, I was a little surprised to find this feature missing. **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** Implement a simple `add_child_at` which takes an index parameter in addition to the child. E.g. ``` # Add child at index 0 parent.add_child_at(child, 0) ``` **If this enhancement will not be used often, can it be worked around with a few lines of script?:** It's pretty fast to work around with `add` then `move`, but tree mutations seem like common enough operations to be worth adding. If we think `add_sibling` was a common enough use-case, then this seems pretty reasonable too. **Is there a reason why this should be core and not an add-on in the asset library?:** Complements existing core functionality.

Posted by andy-noisyduck on Jul 1, 2020, 3:24 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments

github (Software)

Add a `Node.add_child_at()` method to add a node at a specific index

andy-noisyduckJul 1, 2020, 3:24 PM

**Describe the problem or limitation you are having in your project:** There is currently no way to directly add a child at an arbitrary index. The options we are have are either: 1. `add_child` then move it with `move_child` 2. Use `add_child_below_node` to specifiy a sibling. This method is already pretty poor and [has been replaced](https://github.com/godotengine/godot/issues/19642) with `add_sibling` in `master`, and it doesn't allow you to add a node at index 0 because the new node is added after the sibling. Honestly, I was a little surprised to find this feature missing. **Describe the feature / enhancement and how it helps to overcome the problem or limitation:** Implement a simple `add_child_at` which takes an index parameter in addition to the child. E.g. ``` # Add child at index 0 parent.add_child_at(child, 0) ``` **If this enhancement will not be used often, can it be worked around with a few lines of script?:** It's pretty fast to work around with `add` then `move`, but tree mutations seem like common enough operations to be worth adding. If we think `add_sibling` was a common enough use-case, then this seems pretty reasonable too. **Is there a reason why this should be core and not an add-on in the asset library?:** Complements existing core functionality.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue