DEV Community

KENTO⚽️XR Engineer😎
KENTO⚽️XR Engineer😎

Posted on

3

【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?

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay