So I have a script that, when i put in on an object, it changes the materials of all the children of that object (inlcuding children of children).
I may have this structure:
root object with the script
— level 1 child
— level 1 child
------ level 2 child
------ level 2 child
--------- level 3 child
All the materials of these direct children and deep children will be changed.
The thing is that I want an event to know when let’s say a child from level 2 or level 3 is removed from this mini-hierarchy, so that I change the materials back to what they were before.
I know that OnTransformParentChanged() is called when a gameobject’s parent changed, but I cannot use this function, as I do not want to attach a script to all these children. I want to have only the script on my root object.
There is also OnTransformChildrenChanged() that I can overwrite in the script of the root object, but this gets called only when a level 1 child changed its parent.
How would you guys do this? I would like some sort of an event that works like OnTransformChildrenChanged() that also works with deep children, but please tell me if you have another solution. (PS, I would like to not use Update to constantly check)