Browse Source

Made get_child support negative indexes, with documentation

SekoiaTree 5 years ago
parent
commit
bdf614d3d7
2 changed files with 4 additions and 0 deletions
  1. 1 0
      doc/classes/Node.xml
  2. 3 0
      scene/main/node.cpp

+ 1 - 0
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>

+ 3 - 0
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];