-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ScriptableObject: Support undocumented event function void OnValidate()
#79
Comments
Do you have any details on who invokes this method? It would be nice to work out visibility (public private), static modifiers and parameters to be sure I've added the function correctly. |
OnValidate's behavior on ScriptableObject is the same as on MonoBehaviour. OnValidate is a non-static method which is invoked from native and isn't picky about visibility (it'll get invoked regardless of visibility). OnValidate is different from the other magic methods in that it only gets invoked from the Editor. A good practice is to wrap OnValidate with #if UNITY_EDITOR so that the function can be stripped out for deployment. To expand on ScriptableObject a bit. Native Unity code doesn't distinguish between MonoBehaviour and ScriptableObject. They are the same native type (it's confusing, I know, and everyone gets tripped up by it that looks at the native code base). The only difference is in how the object is used, MonoBehaviours live on GameObjects, while ScriptableObjects can live alone. So in general, all magic methods that would make sense without a GameObject context should work and be implemented for ScriptableObjects. Off the top of my head this includes, Awake, OnEnable, OnDisable, OnDestroy, OnValidate, and Reset, but there could be more. |
Great info, thanks! I like the idea of wrapping editor specific functions in I've already got |
Unfortunately, not really a good way to get a list. Either manually try out each MonoBehaviour event to see if it works, or someone (like myself) with source will need to dig into it and see which ones are actually used for ScriptableObject. I'll see if I can dig into it sometime this week. |
Any info you can throw our way about the messages would be great - I'm currently scraping several versions of the docs to build the data I'm using, and that doesn't include info on what's only used by the editor, or what messages can also be coroutines. |
Support for the event function
void OnValidate()
on ScriptableObject is missing, probably because it undocumented.The text was updated successfully, but these errors were encountered: