diff options
author | SekoiaTree <sequoia.1009@gmail.com> | 2020-08-25 14:46:33 +0200 |
---|---|---|
committer | SekoiaTree <sequoia.1009@gmail.com> | 2020-09-01 11:34:36 +0200 |
commit | bdf614d3d75551164fdd1eed7fb5539cafa30330 (patch) | |
tree | 7b929a776ad4cd56629c73d137c96119730f3cd2 | |
parent | 603febdbfef2d4553eb22e545d3094142b5eaab3 (diff) |
Made get_child support negative indexes, with documentation
-rw-r--r-- | doc/classes/Node.xml | 1 | ||||
-rw-r--r-- | scene/main/node.cpp | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 8f66c9df38..72088e89d1 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -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> diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 653eb698d4..6b304c03d2 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -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]; |