mirror of https://github.com/godotengine/godot
Merge pull request #41505 from SekoiaTree/neg-get-child
Made get_child support negative indexes
This commit is contained in:
commit
877246a78e
|
|
@ -215,6 +215,7 @@
|
||||||
</argument>
|
</argument>
|
||||||
<description>
|
<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.
|
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].
|
To access a child node via its name, use [method get_node].
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
|
|
||||||
|
|
@ -1327,6 +1327,9 @@ int Node::get_child_count() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *Node::get_child(int p_index) 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);
|
ERR_FAIL_INDEX_V(p_index, data.children.size(), nullptr);
|
||||||
|
|
||||||
return data.children[p_index];
|
return data.children[p_index];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue