• 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 Shegon · Nov 07, 2015 at 09:25 PM · rotationactivedetect

Check if gameObject is active not working

I have a heirarchy of game objects that have their active status animated. I'm trying to check if these objects are active, and if they are, I'm trying to reset their rotation to 0, 0, 0. I've been running some tests to basically print "inactive" when the object is inactive, but I can't seem to get the script to detect the active status. I've tried:

if (gameObject.active == false) if (gameObject.activeInHierarchy == false) if (gameObject.activeSelf == false)

But none of these seem to trigger my script. Any ideas? Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rageingnonsense · Nov 07, 2015 at 10:09 PM

You didn't specify, but if you are trying to run this on the GameObject that you have inactive, the code is never going to run because events are not run for inactive game objects.

You would have to have a separate script attached elsewhere that keeps track of them, and loops through them checking the status. If you have a parent game object with a script attached, and make all of these children, it could be as simple as:

 foreach{Transform child in transform) {
     if(child.gameObject.active) {
         Debug.Log(child.gameObjet.name + " is active");
     } else {
         Debug.Log(child.gameObjet.name + " is inactive");
     }
 }

In the parent's script

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

33 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

Related Questions

Rotation of the mouse activates a boxcollider2d in javascript. 1 Answer

Flip over an object (smooth transition) 3 Answers

how to count spins of the object 2d C sharp ? 0 Answers

Detecting the range between 2 angles 2 Answers

Detecting a certain degree angle? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges