Skip to content

Instantly share code, notes, and snippets.

@adamski11
Last active April 9, 2026 13:56
Show Gist options
  • Select an option

  • Save adamski11/ff3bc5e77526be72b52fb1ee752cc082 to your computer and use it in GitHub Desktop.

Select an option

Save adamski11/ff3bc5e77526be72b52fb1ee752cc082 to your computer and use it in GitHub Desktop.
Get Active Sibling Index - Use this script to create the extension method GetActiveSiblingIndex which allows you to find the sibling index whilst ignoring inactive siblings. Useful for animations that are meant to run in sequence, but have unusual delays caused by inactive sibling changing the numbers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class GetActiveSiblingIndexScript {
public static int GetActiveSiblingIndex(this Transform transform)
{
int index = 0;
for (int i = 0; i < transform.parent.childCount; i++)
{
Transform nextChild = transform.parent.GetChild(i);
if (!nextChild.gameObject.activeSelf)
continue;
else if (nextChild == transform)
return index;
else
index++;
}
return index;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment