What should I do when a method fail to return a GameObject?

I am creating a static method to get a reference to a certain type of Gameobject that can be accessed from various scripts.

public static Vehicle GetVehicleInScene() 
{
    Vehicle v = GameObject.FindObjectOfType<Vehicle>();
    return v;
}

Now, if the object is already destroyed or no longer exist in the scene, how should I do a ‘safe’ return?

if (!v) return null;

The other alternative is to create the GameObject you wish to return.

I’m pretty sure FindObjectOfType returns null if it can’t find an object, so the simplest way to do it would be:

if (v)   // if not null
   return v;
else
   return null;

Thinking about it, this is exaclty the same as just doing return v; … You could check the value upon return from the method to make sure the object you’re trying to use is not null, e.g:

Vehicle v = yourScript.GetVehicleInScene();

if (v) 
   // If not null, do stuff