- Home /
Is "GameObject.FindAllGameObjectsWithTag" related to the hierachy?
So I need to do similar things to lots of game objects. I have positioned them in the hierarchy in the order i want them to be found with "GameObject.FindAllGameObjectsWithTag". They just appear to be found randomly. Is there a way I can make sure they are found in a certain order? eg: 1st GameObject name in hierachy is called test_one allgo[0].name returns test_one
Thanks for any replies
What are you trying to solve with your ordering? If they're all children of the same object, you can simplify this greatly.
Anything with GameObject.Find
is going to be expensive, so much so that Unity's developers probably have the search itself optimized to the point where hierarchy order can't be considered.
So I have 2 lists and the position in the list of the gameobject deter$$anonymous$$es the element number in list two, which changes parts of the gameobject. Thanks for fast reply.
A dictionary does that for you. No need to use two lists.
Answer by myzzie · Sep 04, 2018 at 05:07 PM
I don't know about the order, but IIRC, gameobjects are stored in sections with same tag, so when you call findobjectwithtag it only looks in the section with that tag and skips all other gameobjects with different tag.
You can put the gameobjects in an array/list and iterate that.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Need help finding the closet player to an enemy 2 Answers
GameObject.Find, When it is Called? 1 Answer
Multiple Cars not working 1 Answer