Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 14, 2014 at 08:18 AM by Kiwasi for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Developug · Oct 14, 2014 at 05:43 AM · gameobjectfindflagged-for-delete

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

i wonder why unity doesn't make this method?

why??? plz, tell me a reason.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image revolute · Oct 14, 2014 at 05:56 AM 0
Share

There is GameObject.Find. So why do you even want something that you can do?

avatar image JanusMirith · Oct 14, 2014 at 06:10 AM 0
Share

If you told us what you wanted to do and why, with specifics we could help you.

We should not need to guess what you wanted from your question.

avatar image Kiwasi · Oct 14, 2014 at 08:21 AM 0
Share

Unity Answers is not a place to challenge Unity's design intentions or ask for features. You may be able to get a developers attention on the forums.

UA is for specific technical questions, not discussion of features.

Edit: If your question is "How can I find disabled GameObjects by name?" then ask that question.

avatar image Developug · Oct 14, 2014 at 11:22 AM 0
Share

Bored$$anonymous$$ormon // Thanks!

3 Replies

  • Sort: 
avatar image
0

Answer by Cynikal · Oct 14, 2014 at 05:59 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by fafase · Oct 14, 2014 at 06:26 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by WTPS · Oct 14, 2014 at 08:14 AM

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
                     }
             }
     }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Oct 14, 2014 at 08:21 AM 0
Share
 public GameObject[] GameObjectFind (string name, Transform parent, bool isActive)
 {
    if (string.IsNullOrEmpty (name)) 
    {
         return;
    }
    if (parent == null) 
    {
         return;
    }

    List<GameObject> list = new List<GameObject>();
    foreach(Transform t in parent)
    {
        if(t.gameObject.activeSelf == isActive){
            lit.Add(t.gameObject);
        }
    }
    return list.ToArray();
 }

But I don't think that is what he is after :).

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

"GameObject.Find();" not working 2 Answers

Creating a single-line function for GameObject.Find and GetComponent (for multiple components) 3 Answers

Find Define GameObject Problem. 2 Answers

How to create array of GamwObject 0 Answers

Detect when instance has deleted 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges