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.
This commit is contained in:
parent
7924d643e5
commit
665621aa1b
1 changed files with 2 additions and 1 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue