Editor Extensions: GameObject.Find & More Info?

Hello!

Is there a way to find out if a game object exists? I’d like to create an empty game object by name (such as “Actors”) if the game object “Actors” doesn’t already exist. I 've found code for creating it, but not for finding it.

I’ve found the Scripting API for editor extensions, but I’m wondering if there’s a more developed guide somewhere out there? Preferably in UnityScript – that’s my strong suit and I’d be getting my brother to translate the code to C# if I finish what I’m working on.

Thanks!

It’s been a couple years since I’ve last programmed in Unityscript so it’s a bit rusty. Here’s how you do it in C#.

private void InstantiateIfNull(string gameobjectName) {
    if(GameObject.Find(gameobjectName)) return;
    new GameObject(gameobjectName);
}

In your case you would use it like below

InstantiateIfNull("Actors");