How to make my own OnValidate()

OnValidate() when calling GetComponentInParent throws an error.
In general, I guess the error may be due to the fact that objects are loaded at different times and therefore randomly causes an error. And so I have the following question:

How to make my own OnValidate(), it should be called only after saving the changes to the current class (or assembly). Please tell any ideas (it must be not-static method). Thanks

You can probably use AssetModificationProccessor.OnWillSaveAssets: Unity - Scripting API: AssetModificationProcessor.OnWillSaveAssets(string[])

Or use a custom inspector, which is generally how you should do more robust data validation.

1 Like