- Home /
Object active despite parent being inactive. Workaround perhaps?
So i was running some tooltips in varius windows, and i noticed these tooltips still appeared despite having closed the window in my code.
So i look into it and find that despite me deactivating the container the objects that the tooltip script was on - any child object of the deactivated parent was still considered active?
So as to my question, barring literally putting some script to auto-deactivate based on parents activation (which seems incredibly inefficient and also not good incase i want this feature as intended) - is there any other way ? Perhaps im missing something in the inspector that sets the activation of the object equal to its parent?
Because if you have 100s if not 1000s of objects, looping through each with a script (not even mentioning having to know what object the script is on and/or if you missed one, this seems like a huge oversight.
so what can i do? And what would the most efficient solution be? TLDR: Child remains active, despite de-activating parent, which creates a bug because script keeps running due to that fact.
I have already tried in code checking the object, and checking the parent would be incredibly hard due to tooltips being on several different menu's with different parents. Thankyou for your time!
Answer by sath · May 04, 2020 at 01:48 PM
If the child script has a function that is being called by some other script the most appropriate workaround is to put if(!gameObject.activeInHierarchy) return;
at the beginning of that function.
I didnt even know .activeInHierarchy was a thing! Thankyou, that alone solved my problems, since i can simply check for it being active that way, i was just using activeSelf. Good answer!
Your answer
Follow this Question
Related Questions
Script Two Button Functions At Once 1 Answer
Dropdown box not working when setting active 1 Answer
Second Player Cannot Navigate the Menu 2 Answers
UI Buttons - affects all 0 Answers