FindObjectsOfType vs FindObjectsByType

Unity has seemingly endless ways to get objects in the scene. Out of curiousity I wanted to understand why there are so many similar looking methods. I also noticed we use FindObjectsOfType instead of FindObjectsByType but perhaps because the “By” variant didn’t exist in Unity 2018.

As of now, Unity recommends the By vs the Of variant. Why? Because the former doesn’t maintain any sort order (at least by default) and sorting a large list is expensive. I remember which one to use with this simple trick. “By” default, I use the “By” Type variant.

Here are the relevant references from Unity docs:

Privacy & Terms