When to create a new instance

I am going through Will Goldstone's tutorials and came across the following:

var theHouse = gameObject.FindWithTag("house1"); 

I was wondering if we must create the instance or if we could simply to this directly like this


Thanks in advance

You're not creating an instance, you're just assigning the instance to a variable (There is a pretty large difference if you're going for correct terminology)

His way lets you check if theHouse isn't null, which is very useful if you're not sure your object actually exists (which lets you throw your own errors instead of exceptions being thrown)

One thing though - use GameObject.FindWithTag instead of gameObject.FindWithTag. It's a bit of a freaky javascript only thing where it lets you access the static function of a class through an instance. It's also a bit slower as it has to grab the gameobject first