Merge pull request #41505 from SekoiaTree/neg-get-child

Made get_child support negative indexes
This commit is contained in:
Rémi Verschelde 2020-09-01 12:35:55 +02:00 committed by GitHub
commit 877246a78e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View file

@ -215,6 +215,7 @@
</argument>
<description>
Returns a child node by its index (see [method get_child_count]). This method is often used for iterating all children of a node.
Negative indices access the children from the last one.
To access a child node via its name, use [method get_node].
</description>
</method>

View file

@ -1327,6 +1327,9 @@ int Node::get_child_count() const {
}
Node *Node::get_child(int p_index) const {
if (p_index < 0) {
p_index += data.children.size();
}
ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr);
return data.children[p_index];