Check if GameObject.Find returns null

When I use GameObject.Find, could I, in a script, check if that functions returns void?

So in other words can I create an if statement that checks if a certain gameobject is not found in the hierarchy?

Thanks

Alex

Ofcourse,

This function only returns active GameObjects. If no GameObject with name can be found, null is returned.

var item = GameObject.Find("test");
if (item == null) 
//do whatever

For performance reasons, it is recommended to not use this function every frame. Instead, cache the result in a member variable at startup. or use GameObject.FindWithTag.

Note: If you wish to find a child GameObject, it is often easier to use Transform.Find.