This is a bit of a rare issue. But I figured it may certainly be useful for individuals that come across this problem. You want OnValidate to be called on a parent object when you make changes from a child object. So when you change a component or add one in a child component, you will get a callback on the root object.
Currently there is one limitation on the script, it only works if the script is on the root of an object. This will/can change in the future if there is enough demand for it. I currently don’t have the time to implement this modification.
I’ve made a simple script that does just that. It is called Unity Validate Hierarchy and you can download it here on Github or you can get a direct download link here. You can read below on how you can use the script.
How can I implement it in my script?
First, you have to implement the using statement:
using Lowscope.Tools;
In order to have it work on any of your scripts, you have to add the following lines within the OnValidate method of your script
ValidateHierarchy.Add(this)
Also important, you have to add this line in OnDestroy() so it gets unsubscribed on scene change.
ValidateHierarchy.Remove(this)
And you are done! Now OnValidate() is called when a child object has a component added or removed. Thank you for reading.
Why did I make this script?
An older of this script is currently used in Health Pro. The reason for creating it was because Health Pro, and a upcoming save system both try to fetch scripts from child objects during editor-time. Using this script makes it easy to update once a child object has been added or removed.