Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
3
Question by dreamhex · Mar 17, 2015 at 03:46 PM · gameobject.find

Find inactive game object.

Hi guys, is there some way to find inactive game object? I don't want to use drag and drop in editor and GameObject.FindWithTag finds only active game objects. Is there some way I don't know about or do I have to set them active at start and deactivate them later.

Comment
Add comment · Show 3
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 MagicZelda · Mar 17, 2015 at 03:48 PM 0
Share

i actually reposition to some far out of the way place rather than inactive. Solved the issue for me.

avatar image dreamhex · Mar 17, 2015 at 03:53 PM 0
Share

yeah I am thinking about active at start off the screen, then deactive and change position where I need, but would have been easier I could find inactive objects with GameObject.FindWithTag

avatar image kskjadav007 dreamhex · Apr 13, 2018 at 10:30 AM 0
Share

you can add objects into one list before deactivate and active them again

7 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer Wiki

Answer by JiMMaR · Mar 17, 2015 at 04:58 PM

As far as I know, you can't.

you can however start as active and reference them in your code before you deactivate them.

you could also try referencing their parent [if it was a transform] and then iterate over the children if that's not a bad thing in your case

Comment
Add comment · Show 4 · 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 dreamhex · Mar 17, 2015 at 05:19 PM 0
Share

Thanks, I did the first one (active at start and deactivate later) , I have read some older posts from 2007-2013 where people suggested there should be way to find inactive objects and I wanted to be sure. I guess it would make some mess if we could do that with GameObject.FindWithTag.

avatar image ryrich · Mar 17, 2015 at 06:32 PM 2
Share

You could also start as active, and when deactivating, add to a "deactivated list" - or a grosser way would have all game objects be children of a "root" parent, and then you can use GetComponentsInChildren (which has an additional includeInactive argument)

avatar image karn1412 · Oct 31, 2015 at 12:59 PM 0
Share

Oh, i feel so dumb now. Thank you so much man.

avatar image Whiteleaf · Nov 24, 2015 at 07:01 PM 0
Share

thanks for this! I couldn't figure out how to get object information from objects I had instantiated and were by default inactive due to it's parent. i created the objects in awake, and then turned the parent object on in awake after i created them so that my other script could get the data from them in it's start function. then i disabled the parent object on start..

avatar image
2

Answer by darkhog · Jan 07, 2016 at 05:20 PM

If anyone will have this issue, here's what I've used to resolve this problem:

 GameObject filenamefld = null;
 Transform[] trans = GameObject.Find("EditorGUI").GetComponentsInChildren<Transform>(true);
 foreach (Transform t in trans) {
     if (t.gameObject.name == "FileNameFLD") {
         filenamefld = t.gameObject;
     }
 }

You may want to put that into its own function, but since I've used it only in one place, this is sufficient. EditorGUI is "root object" and FileNameFLD is object we actually want to find. Hopefully this is useful.

Comment
Add comment · Show 2 · 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 JiMMaR · Jan 07, 2016 at 09:02 PM 0
Share

I don't think this will find nested inactive children, try and confirm also you would probably want to break out of the loop after you find your object

avatar image lawrence_laz · Feb 20, 2017 at 06:56 PM 2
Share

Or use a one-liner:

 GameObject.Find("ActiveParentsName").transform.Find("InactiveChildsName").gameObject;
avatar image
1

Answer by Noob_Vulcan · Jul 25, 2015 at 05:54 AM

For more ways you can refer this http://www.unityrealm.com/how-to-find-inactive-gameobject-in-unity/

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 pamelacook · Jul 30, 2018 at 08:01 PM 0
Share

Note: This link no longer exists.

avatar image
-1

Answer by Sw_Architect · Apr 13, 2018 at 07:28 AM

first of all active the object and get in Awake() then simply disable it in Start();

e.g

void Awake(){ GameObject game=getcomponent();

} void Start(){ game.setActive(false); }

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

Answer by badadam · Jan 14, 2019 at 02:15 PM

I give you extraordinary solution. Add the script below to your inactive object as a component.

     public class InactiveObject : MonoBehaviour {
 
      public static InactiveObject instance;
 
      public InactiveObject()
      {
           instance = this;          
      }
 
     public void makeActive()
      {
           gameObject.SetActive(true);
      }
 }

When you want to set the game object active, you can run the code below from another script

  InactiveObject.instance.makeActive();
 

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 Bonfire-Boy · Jan 14, 2019 at 03:42 PM 0
Share

This is a really bad "solution". For starters, it would require a separate class of this sort being created for each individual object that you wanted to be able to find.

Also, you're giving a $$anonymous$$onoBehaviour class a constructor. Don't do that!

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

34 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

Related Questions

How to find all objects with an tag and change an value in all of them? 1 Answer

Problems with cloning, aka double trouble. 0 Answers

Need an alternate to Gameobject.Find 2 Answers

Prefab Initiated At Beginning Of Game Returns Error When Script On Prefab Attempts To Find A Gameobject In Game 1 Answer

GameObject.Find() Question 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