Made get_child support negative indexes, with documentation

This commit is contained in:
SekoiaTree 2020-08-25 14:46:33 +02:00
parent 603febdbfe
commit bdf614d3d7
2 changed files with 4 additions and 0 deletions

View file

@ -213,6 +213,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];