• 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
1
Question by AmazingDeveloper2 · Feb 05, 2015 at 02:49 PM · gameobject

Check if GameObject.SetActive(true/false)

I have a GO in my script:

 GameObject object1;

I enable/disable it using SetActive(true/false).

And I want to check if it enabled or disabled. Something like this:

 if(object1.enabled) { ... }

How can I do it?

Comment
Add comment · Show 2
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 chariot · Feb 05, 2015 at 02:55 PM 0
Share

try object1.active or object1.activeSelf in your check construction

http://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html

/в общей попробуй оба заюзать, они вроде как только читабельные/

avatar image AmazingDeveloper2 · Feb 05, 2015 at 02:58 PM 0
Share

Спасибо, помогло

3 Replies

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

Answer by PrisVas · Feb 05, 2015 at 02:55 PM

Try GameObject.activeInHierarchy

http://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html

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 AmazingDeveloper2 · Feb 05, 2015 at 02:58 PM 1
Share

Thanks, it helped

avatar image $$anonymous$$ · Aug 13, 2015 at 06:26 PM 0
Share

Yeah! Simple and functional :D

avatar image RAMBITO · Feb 06, 2017 at 06:51 PM 0
Share

as?? if (obj1.activeInHierarchy (false) ) ?

avatar image PrisVas RAMBITO · Feb 06, 2017 at 06:55 PM 1
Share
 if (obj1.activeInHierarchy == false )

or

 if (!obj1.activeInHierarchy)
avatar image
0

Answer by felixhdyw · Oct 24, 2018 at 06:46 PM

THANKS A LOT! this is what im trying to do

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
11

Answer by mikembley · Feb 05, 2015 at 03:31 PM

 GameObject.activeSelf;         //Returns if the object is active or not
 GameObject.activeInHierarchy;  //Return if the object is active in the scene
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 Carterryan1990 · Feb 23, 2018 at 08:34 PM 0
Share

Thanks! Couldn't figure it out due to the parent object being inactive but the child object is active so the GameObject.activeSelf was the solution! appreciate it!

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

25 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Make the gameobject flip to the direction it is being dragged to? 1 Answer

Efficiency of Game Loops 2 Answers

GameObject as a constraint for generic class 1 Answer

Multi object detection with single ray cast 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