Question by
patrik-org · May 05, 2016 at 08:06 PM ·
c#components
Is there a way for children to know if a parent is deactivated?
I want children (components) to be notified when they are deactivated (e.g. if their parent is deactivated), is there an event that children can listen to or do I need to notify the children manually on deactivation?
If no event, is there a way for a child to check if it's active in the scene (if it or its parent has been deactivated)?
Comment
Best Answer
Answer by patrik-org · May 05, 2016 at 08:52 PM
The solution was to use:
public void OnDisable()
{
// called when this or a parent object is deactivated
}
Answer by FortisVenaliter · May 05, 2016 at 08:19 PM
Not sure about the events, but every GameObject has a field activeInHierarchy and activeSelf, and you can access the parent through transform.parent.gameObject.
Thanks for your answer, activeInHierarchy is helpful. I found a solution to be informed when it happens.