- Home /
How to determine order of object list collection from scene
I assumed this would take the objects from the scene in order listed on Hierarchy but no?? What method? I have hero1 hero2 hero3 on scene view 1st to last so I though it would set heroes[0] to hero1 heroes[1] to hero2 heroes[3] to hero3
but it adds the object to the list in a way that I do not understand
Thanks
GameObject[] objects = GameObject.FindGameObjectsWithTag("HeroPrefab");
foreach (GameObject tempObjects in objects)
{
Vector3 ps = tempObjects.transform.position;
heroes.Add(tempObjects);
}
I would suggest you give your heroes an ID of some sort, and have your heroes' scripts implement ISortable
.
Answer by NoseKills · May 05, 2014 at 06:50 PM
This can be used if you don't need to do it repeatedly... like every frame http://answers.unity3d.com/questions/369411/how-to-sort-a-list-of-gameobjects-by-their-name.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613144254im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best workflow for DontDestroyOnLoad method regarding Unity Editor? 1 Answer
Using empty gameobjects as "folders" in scene hierarchy panel 1 Answer
How can I permanently display (`EditorApplication's) current scene name in Editor? 1 Answer
Monodevelop deleted my hierarchy/scene 2 Answers
In the Hierarchy how do I find an object with a certain script attached 2 Answers