diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 429a9abf51b..b8824259609 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -241,7 +241,7 @@ 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. - If [param include_internal] is [code]true[/code], internal children are skipped (see [code]internal[/code] parameter in [method add_child]). + If [param include_internal] is [code]false[/code], internal children are skipped (see [code]internal[/code] parameter in [method add_child]). To access a child node via its name, use [method get_node]. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs index 1dc21b6303b..df0e8398660 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs @@ -93,8 +93,12 @@ namespace Godot /// Negative indices access the children from the last one. /// To access a child node via its name, use . /// - /// + /// /// Child index. + /// + /// If , internal children are skipped (see internal + /// parameter in ). + /// /// /// Thrown when the given the fetched node can't be casted to the given type . /// @@ -102,9 +106,9 @@ namespace Godot /// /// The child at the given index . /// - public T GetChild(int idx) where T : class + public T GetChild(int idx, bool includeInternal = false) where T : class { - return (T)(object)GetChild(idx); + return (T)(object)GetChild(idx, includeInternal); } /// @@ -113,15 +117,20 @@ namespace Godot /// Negative indices access the children from the last one. /// To access a child node via its name, use . /// - /// + /// /// Child index. + /// + /// If , internal children are skipped (see internal + /// parameter in ). + /// /// The type to cast to. Should be a descendant of . /// /// The child at the given index , or if not found. /// - public T GetChildOrNull(int idx) where T : class + public T GetChildOrNull(int idx, bool includeInternal = false) where T : class { - return GetChild(idx) as T; + int count = GetChildCount(includeInternal); + return idx >= -count && idx < count ? GetChild(idx, includeInternal) as T : null; } ///