Checking if a gameobject is active

Hello, I am wondering how to CHECK if a gameobject is active.

Thanks!

4 Likes

gameObject.activeSelf is true if its active and false if its not.
However, and object can be active, but if its parent is not active it will function as if it were inActive.
you can check this with
gameObject.activeInHierarchy This is true if the object is active AND all its parents are active.

25 Likes

Many thanks for the short and very helpful information!

2 Likes

how do you check if its not active

Like this for example:

        void CheckGameObject()
        {
            if (!yourGameObject.activeSelf)
            {
                // do something, if it is not active...
            }
            else
            {
                // do something, if it is active...
            }
        }
3 Likes