DEV Community

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

Posted on

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