Difference between isActiveSelf and ActiveInHierarchy

I am doing the new Realm Rush and Gary, uses

private void EnableObjectInPool()
{
for(int i = 0; i < pool.Length; i++)
{
if(!pool[i].activeInHierarchy)
{
pool[i].SetActive(true);
return;
}
}
}

For my solution i used isSelfActive instead of activeInHierarchy. It seems to work in the same way, but was wondering is there a reason why I should use ActiveInHierarchy over isSelfActive ? Or is it just horses for courses? I checked on Stack Overflow and just got more confused :slight_smile:

So if anyone could help me out, it would be much appreciated :smiley:

Hi Paul,

The game object itself could be marked as “active” while it is not active in the Hierarchy because its parent is inactive.

Do you remember the Rocket in Project Boost? It had child game objects with the visual elements. Imagine we disabled the parent (Rocket). The children would still be marked as “active” in their respective Inspector, which is what we want because if we enable the parent, we want to see the children.

The parent could be active in the Hierarchy but we could have disabled the children (isSelfActive), and the result of the child would be: isSelfActive is false, activeInHierarchy is false.

It seems to work in the same way, but was wondering is there a reason why I should use ActiveInHierarchy over isSelfActive ?

They give the same result in certain cases, so to answer your question, you will have to answer this question as well: Are you interested in the state of the game object itself or in the state of the game object within the context of the scene?

Did this clear it up for you?


See also:

Hi Nina!
Thank you for the quick reply, yes it has :smiley:
I moved over from the old course to the new Course, and it is different in what it teaches and when. So I am thinking I might go back and redo the sections I already covered in the old format.

Thanks again!!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms