i’ve been wondering what the difference between these 2 is. I’ve seen them both appear and they seem to do exactly the same. The best explaination i could come up with is that the code got rewritten and they didn’t remove the old function. Also there is no information whatsoever on GameObject.FindGameObjectWithTag(Tag tag) in the referece manual.
I ran a performance test, 1000 cubes, one of them had the “Player” tag and ran the following code.
public class FindPerformanceTask : MonoBehaviour {
// Use this for initialization
void RunTest () {
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
for (int i = 0; i < 1000000; i++) {
GameObject player = GameObject.FindGameObjectWithTag("Player");
}
stopWatch.Stop();
Debug.Log(stopWatch.ElapsedMilliseconds.ToString()+"ms");
}
void Update()
{
if(Input.GetKeyDown(KeyCode.Space)){
RunTest();
}
}
}
The Science is in! Both perform the same.
they both do exactly the same thing.
GameObject.FindGameObjectsWithTag
Finds a list of objects.
The other finds only one and returns it.