【Unity】How to get the game objects get using FindObjectsOfType in the same order as the hierarchy.

kento

KENTO⚽️XR Engineer😎

Posted on October 29, 2022

【Unity】How to get the game objects get using FindObjectsOfType in the same order as the hierarchy.

The list get using FindObjectsOfType is not in hierarchy order.
So, if you are important to use order, you must reorder the list.

Sample Code

private void Awake()
{
    var monoComponentList = FindObjectsOfType<MonoComponent>().OrderBy(m=>m.transform.GetSiblingIndex()).ToList();
}
Enter fullscreen mode Exit fullscreen mode

Other Resources

FindObjectsOfType order by hierarchy?

💖 💪 🙅 🚩
kento
KENTO⚽️XR Engineer😎

Posted on October 29, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related