I'm wonderting why FindGameObjectWithTag() return diffent value after build

first of all sorry for my bad english


I’m wonderting why FindGameObjectWithTag() return diffent value after build
for example
i have gameobject “Player” with tag(“Player”)
and another gameobject “Trigger” with same tag (“Player”) that child gameobject of “player”

in editor FindGameObjectWithTag() return “Player”
after build FindGameObjectWithTag() return “Trigger”

i think this difference is come from difference of traverse
in editor preorder traverse
after build anything else traverse

am i right? i wonder correct answer

As per the docs:

Note: This method returns the first GameObject it finds with the specified tag. If a scene contains multiple active GameObjects with the specified tag, there is no guarantee this method will return a specific GameObject.



If you have more than one object with that tag then you need to get all of them using FindGameObjectsWithTag and then select the one you want.


Personally I would just keep a reference to it if its a special case as its going to be more performant.