• 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 /
avatar image
Question by MSachs · Sep 04, 2018 at 11:53 AM · scripting problemgameobjecttagactiveinactive

Finding all GameObjects with the same tag when some of them are inactive?

Hi

Is there a way to find all GameObjects by using their tag even if some of them are inactive at the time?

I have multiple gameObjects with the same tag and if I click on one of them that object will become inactive. I then want to basically reset them all back to their original active state using a button of some sort.

To my knowledge the GameObject.FindGameObjectsWithTag("") function doesn't work on inactive objects. Is there a way to do this in any other way? :)

Thanks in advance

Comment

People who like this

0 Show 0
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

4 Replies

  • Sort: 
avatar image
Best Answer

Answer by Atiyeh123 · Sep 04, 2018 at 12:06 PM

This question has already been answered.

There is no way to find inactive objects with GameObject.FindGameObjectsWithTag("") as you mentioned but you can store inactive objects in an array and and get objects from array is much more performant than using GameObject.FindGameObjectsWithTag("") each time .

these links also answer same question:

https://answers.unity.com/questions/61174/is-there-a-findgameobjectswithtag-that-returns-act.html https://answers.unity.com/questions/1202627/how-to-access-an-inactive-gameobject-with-tag.html

Comment
MSachs

People who like this

1 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 MSachs · Sep 04, 2018 at 12:16 PM 0
Share

Thank you!

avatar image

Answer by Playbosh-Games · Dec 03, 2020 at 01:19 PM

 public static class FindGameobjekts 
 {  
     public static List<GameObject> FindTagObjects(this GameObject parent, string tag)
     {
         List<GameObject> objs = new List<GameObject>(); 
         foreach (Transform t in parent.GetComponentsInChildren<Transform>(true))
         {
            if (t.tag == tag)
            {
                objs.Add(t.gameObject);
            }
         }
         return objs;
     }
 }

Then you can search through scene root objects with it.

 foreach (GameObject rootobj in SceneManager.GetActiveScene().GetRootGameObjects())
 {
      foreach (GameObject _textobj in rootobj.FindTagObjects("TEXT"))
      {
           //Your Magic here
      }
 }

Now you can catch also the inactive gameobjects with spezific tag.

Comment

People who like this

0 Show 0 · 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

Answer by Cristella · May 20, 2021 at 03:02 PM

I did something simpler, made an empty game object and set its' tag to the tag, while modified the child's active state, which is the required object.

 GameObject[] flags = GameObject.FindGameObjectsWithTag("Flag");
         foreach (var flag in flags)
         {
             GameObject go = flag.transform.GetChild(0).gameObject;
             go.SetActive(true);
         }

Comment

People who like this

0 Show 0 · 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

Answer by Adil_Alhilali · May 20, 2021 at 03:18 PM

my advice is never to destroy an object unless you are sure 100% that you will not recall it again.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

193 People are following this question.

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

Related Questions

Physics.OverlapSphere, if statement, gameObject.tag 0 Answers

How to find Inactive GameObject 16 Answers

GameObject.Find() work on inactive objects 16 Answers

Activate gameobject that is deactivated with c# 2 Answers

Toggling a game object between an active and inactive state 1 Answer


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