- Home /
Any way to check if an object is active?
I've used if(theObject.activeSelf == true){} and if(theObject.activeInHierarchy == true){} but I'm not really sure how to use those, if anyone could help me here that would be awesome!
Also, I need it in C#
Answer by united4life · Jan 27, 2014 at 01:07 PM
activeSelf will check for the current gameObject activeInHierarchy will check for the current as well as children of current gameObject
If you want to use activeInHierarchy make sure the child of current gameObject are active
Rest you can read in the docs
http://docs.unity3d.com/Documentation/ScriptReference/GameObject-activeSelf.html http://docs.unity3d.com/Documentation/ScriptReference/GameObject-activeInHierarchy.html
I've read the script references, but I'm still a little confused. Is there a way you could give me an example of how you are supposed to use it?
check the above screen shot
suppose you are checking activeSelf for GameObject_2 it will check whether GameObject_2 is active or not
Now if you want to check the state for GameObject_1 as well as its child i.e cube you have to use activeInHierarchy