I need to validate some data!
Everybody knows that most of editor scripts you created, will be used by people like level designers and game designers. It’s always a good idea to put extra checking to what data they enter while building the scene. They shouldn’t care about values limitations but you have to! 😉
I found a OnValidate function as one of the best ways to validate input data.
How to use OnValidate?
There is only a short description on unity site about OnValidate function and no examples.
In the nutshell – OnValidate function is called in editor mode only on the following cases:
- once script loaded;
- if any value is changed in inspector.
Here’s how to use it in the script: