Baffled by GameObject.FindObjectOfType

I’m having enough trouble with “this”, but I really want to understand this concept before I move on.

levelManager = GameObject.FindObjectOfType();

Is this just a shortcut for something? If so, what?
We’re setting levelManager equal to an object that’s being searched for? What if there’s more than one?

I’ve never felt so dumb. :slight_smile:

Hi @mitchb2,

GameObject.FindObjectOfType() will return the first active loaded object of the specified type, as such you will either get one, or none.

In C# the this keyword is a reference to the current instance of the class.

To out a Unity perspective on it, it is a reference to the MonoBehaviour that is instantiated, e.g the component in it’s GameObject.


See also;