Skip to content

Commit fa1e3e5

Browse files
committed
If child is destroyed we cant get the next one by index anymore
1 parent 42097dd commit fa1e3e5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Scripts/Extensions/GameObjectExtensions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ public static void DestroyChildren(this GameObject gameObject, bool immediate =
2323
int childCount = transform.childCount;
2424
for (int i = 0; i < childCount; i++)
2525
{
26-
var child = transform.GetChild(i).gameObject;
2726
if (immediate)
2827
{
28+
// Child is already destroyed, grab the first one
29+
var child = transform.GetChild(0).gameObject;
2930
UnityObject.DestroyImmediate(child, allowDestroyingAssets);
3031
}
3132
else
3233
{
34+
var child = transform.GetChild(i).gameObject;
3335
UnityObject.Destroy(child);
3436
}
3537
}

0 commit comments

Comments
 (0)