• 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
0
Question by sanks007 · Sep 25, 2013 at 05:51 AM · gameobjectenabled

GameObject and "enabled" ???

Hey guys how to find gameObjects which are disabled.

EDITORS NOTE -- YOU **CAN NOT** "disable" gameObjects. You can set them active or not.} i.e whose enabled property is set to false. [EDITORS NOTE -- gameObjects do not have that property.} This is what i want to do ![image1

As you can see there are three Spheres which are connected with each other.

Now while dragging any of the sphere I disable the Cylinders which connects this Sphere to other spheres.

And after drag is done i want to enable this cylinders again. Something like this

image2.

Here is what i am doing :

 var element2:GameObject=testscript.elementarrays[sphereIndex];
 elementInfo2=element2.GetComponent("ElementInfo");
 Element2=elementInfo2.Element;
                     



firstlayout.png (15.5 kB)
secondlayout.png (19.7 kB)
Comment
Add comment · Show 10
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 robertbu · Sep 25, 2013 at 06:11 AM 2
Share

Something is strange here. You are not disabling the game object. All you are doing is hiding it. The Find() is not failing because you are hiding it, so something else is going on. Verify that the value of connectionId1 is identical in all ways to an existing game object.

avatar image sanks007 · Sep 25, 2013 at 06:32 AM 0
Share

Yup checked everything..The name of each connectionId is same. When i create it ,while dragging the connectionId is same and when i stop drag there as well it is same.As in the picture you can see E-1 has 2 connection. So when dragging the name of would be Connection1 ,Connection2 i.e touch.phase==TouchPhase.$$anonymous$$oved. As touch.phase==TouchPhase.Ended it iterates through the total connection for E-1 which is 2 , it gets name of first connection as Connection1. But when i provide it to Find method.. something like this var connection2=GameObject.Find(connectionId2); it gives me NullReferenceException.

avatar image Fattie · Sep 25, 2013 at 07:13 AM 0
Share

I wish I knew if ENABLED was deprecated or not.

Why are people still using it?

You should be using:

activeInHierarchy Is the GameObject active in the scene?

activeSelf The local active state of this GameObject.

SetActive Activates/Deactivates the GameObject.

avatar image robertbu · Sep 25, 2013 at 07:20 AM 1
Share

@Fattie - actually he is not disabling any game objects. He is only disabling the Renderer...and that is not depreciated.

avatar image sanks007 · Sep 25, 2013 at 07:28 AM 0
Share

As this was not working I also tried GameObject.Active=false and saved the name in an araay(i suppose thats what is meant by keeping reference of each GameObject). And using this value i tried it again.But again the same thing. NullReferenceException. Tried saving GameObjects in the array as well and then finding using this gameobjects. But think this will again give me same problem as i have disabled them so there wont be any reference to them(my thoughts as it gave me the same error).

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Sep 25, 2013 at 07:36 AM

Again, something strange is going on if your Find() is failing with active game objects. Disabling the Renderer does not deactivate a game object. Any chance there is an extra space in the name, or the case is different? Walk the code in the debugger and/or do a Debug.Log() at the point of the Find(). Compare the name in the Hierarchy. Make sure the above script is only attached to the game object(s) you expect.

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 VIPINSIRWANI · Sep 25, 2013 at 07:49 AM

gameobject.setActive(false / true)

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

gameObject.GetComponent("Script").enabled = true not working 5 Answers

Disabling GameObject doesn't disable components 0 Answers

How to make an open and close box?,How to make open and close a box? 0 Answers

Gameobject script enable weird behavior 1 Answer

How can I hide/expose a gameobject based on its distance from the player/camera? 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