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:

1 Like

If you go to the FindObjectsByType() documentation page you’ll find it shows which version of unity it refers to (currently by default it’s 2022.3 (the current LTS release) for the unversioned version of the page). If you click on the version number it opens a small popup where you can select other versions of Unity and it also gives you information on versions for which this page doesn’t apply:

From that you can determine that FindObjectsByType() didn’t exist before Unity 2020.3…

Also, when you compare the list of methods between 2022.3

and 2023.2

you will see that some are missing in 2023.2.

That is because Unity is phasing out the FindObjectsOf...() variants (you get messages they’re marked as deprecated ) in favour of newer the FindObjetsyBy...() methods.

Privacy & Terms