I wanna use Gameobject.Find(string name, bool active)

i wonder why unity doesn’t make this method?

why??? plz, tell me a reason.

I guess the answer is: “Because they chose not to.”

You can come up with your own:

public class Utility{
    public static GameObject Find(string name, bool active = true){
          if(String.IsNullOrEmpty(name))
          {
              return null;
          }
          var go = GameObject.Find(name);
          if(go == null)
          {
               return null;
          }
          go.SetActive(active);
          return go;
    }
}

But you need to call it with :

  GameObject obj = Utility.Find("name", true);

One reason I can see why this method does not do the active part is because it is called Find. The name should reflect the action it does. Actually, your method should FindAndActive to describe what it does. When you read code, you wrap parts of it into method so that it gets easier to read.

var go = GameObject.Find("name", false);

What is false? Is it the activation of the found object? Is it that you are looking only for inactive objects? Is it that you expect a particular output if the search is not successful…? You see that it gets confusing quickly.

Find just finds.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Test : MonoBehaviour
{

    public Transform parent;
	public bool isActive = false;
	public string gameObjectName = "some gameobject";
	public List<GameObject> foundGameObjects = new List<GameObject> ();
	private Transform child = null;

	// Use this for initialization
	void Start ()
	{
			if (parent == null) {
					parent = transform;
			}

			Debug.Log ("Searching inside " + parent.name);
			foundGameObjects.Clear ();//clear list
			GameObjectFind (gameObjectName, parent, isActive);
			Debug.Log ("Found GameObjects (" + foundGameObjects.Count + ")");
	}

	public void GameObjectFind (string name, Transform parent, bool isActive)
	{
			if (string.IsNullOrEmpty (name)) {
					return;
			}

			if (parent == null) {
					return;
			}
	
			int childCount = parent.childCount;
			for (int i = 0; i < childCount; i++) {
					child = parent.GetChild (i);

					if (child.name == name && child.gameObject.activeSelf == isActive) {
							foundGameObjects.Add (child.gameObject);//add to list
					}

					if (child.childCount != 0) {
							Debug.Log ("Searching inside " + child.name);
							GameObjectFind (name, child, isActive);//recursive
					}
			}
	}

}