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
13
Question by Padges · Jan 23, 2011 at 02:39 AM · active

if gameobject is active?

is there a script to check if an object is active or inactive?

something like

if ( gamaeObject =active) { then blah blah blah; }

Comment
Add comment
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

3 Replies

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

Answer by Eric5h5 · Jan 23, 2011 at 02:47 AM

if (gameObject.active)

Comment
Add comment · Show 7 · 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 Padges · Jan 23, 2011 at 03:09 AM 0
Share

specifically. Im wanting to check if a certain gameobject is active, and then act upon whether it is on or off. like can i check if a gameobject with a tag is active?

avatar image Jesse Anders · Jan 23, 2011 at 09:44 AM 0
Share

Your original post shows that you already know how to evaluate a conditional and then act upon the result, so just do that, except with the conditional that Eric showed you.

avatar image Padges · Jan 23, 2011 at 03:56 PM 0
Share

the object im looking to access is froma separate gameobject.

i need to know how to do something like

if (gameobject.Deagle.Active) { act; }

avatar image Jesse Anders · Jan 23, 2011 at 06:31 PM 1
Share

Read this: http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html.

avatar image UDN_bf524d4e-2e97-40ca-829b-a6adec1daa76 · Aug 02, 2016 at 06:09 PM 0
Share

Thanks Dude

Show more comments
avatar image
55

Answer by Kmulla · Apr 04, 2014 at 02:01 PM

As of Unity 4.0 gameObject.active is obsolete and is replaced by gameObject.activeSelf

Source: http://docs.unity3d.com/Documentation/Manual/UpgradeGuide3540.html

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 youblistermypaint · Sep 25, 2015 at 04:59 PM 6
Share

You actually want to use gameObject.activeInHierarchy to get the same behavior as gameObject.active. See http://answers.unity3d.com/questions/543560/does-active-getter-default-to-activeself-or-to-act.html.

avatar image OlafsOsh youblistermypaint · Apr 20, 2021 at 02:40 PM 0
Share

@youblistermypaint 's answer is correct nowadays.

avatar image
5

Answer by tkamruzzaman · Nov 21, 2015 at 07:05 AM

You can use "GameObject.activeSelf": The local active state of this GameObject. Link: http://docs.unity3d.com/ScriptReference/GameObject-activeSelf.html

 if(GameObject.activeSelf)
 {
     print("GameObject is Active");
 }



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 RAMBITO · Feb 06, 2017 at 06:49 PM 0
Share

And with the inactive objects??

avatar image johnCpr RAMBITO · Feb 13, 2017 at 11:16 PM 1
Share

RA$$anonymous$$BITO use " ! " before the GameObject.activeSelf ex:

     if(!GameObject.activeSelf)
      {
     
     }

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

12 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Set npc to active in same position as previous npc (script not working) 1 Answer

'active' is not a member of 'System.Type'. 2 Answers

Set npc to inactive when certain distance away from controller (script not working) 0 Answers

How to import the object from server to unity 2 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