Unity has two functions, with seemingly identical purposes, for finding an object by type.
Object.FindObjectOfType<T>()
which has been around forever.The first active loaded object that matches the specified type. It returns null if no Object matches the type.
There's also an overloaded version which accepts a single boolean argument indicating whether to search inactive objects.
FindObjectOfType<T>(bool includeInactive)
.Object.FindFirstObjectByType<T>()
which I think is newer:Returns the first active loaded object that matches the specified type. If no object matches the specified type, returns null.
There's also an overloaded version which accepts a single enum argument indicating whether to search inactive objects.
FindFirstObjectByType<T>(FindObjectsInactive findObjectsInactive)
;
These functions seem to serve identical purposes, with the only difference between them being that FindObjectOfType()
's overload (rather pointlessly) takes an enum argument instead of a boolean argument.
What's the difference between these two functions? Why do both exist?