summaryrefslogtreecommitdiff
path: root/modules/mono/glue/GodotSharp
diff options
context:
space:
mode:
authorRaul Santos <raulsntos@gmail.com>2022-02-25 01:08:09 +0100
committerRaul Santos <raulsntos@gmail.com>2022-08-24 10:10:47 +0200
commit665621aa1b6b3555ec3aceaad3c6e216cdd8cfdc (patch)
tree61dea1ace83b7ddd686308c627f3ea56881b17dc /modules/mono/glue/GodotSharp
parent7924d643e53a1371836f3e3ec65e706d315f53e9 (diff)
Avoid printing an error in GetChildOrNull
`GetChildOrNull` won't print an error when the given index is out of range, similar to how the LINQ `ElementAtOrDefault` method works.
Diffstat (limited to 'modules/mono/glue/GodotSharp')
-rw-r--r--modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs3
1 files changed, 2 insertions, 1 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs
index e9d8b98344..df0e839866 100644
--- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs
+++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Extensions/NodeExtensions.cs
@@ -129,7 +129,8 @@ namespace Godot
/// </returns>
public T GetChildOrNull<T>(int idx, bool includeInternal = false) where T : class
{
- return GetChild(idx, includeInternal) as T;
+ int count = GetChildCount(includeInternal);
+ return idx >= -count && idx < count ? GetChild(idx, includeInternal) as T : null;
}
/// <summary>