User defined compile time errors?

Is it possible to throw an error to the unity editor at compile time? For example, you might want to throw an error if a public dependency is not set or if just in general you have an invalid value for a public property. Right now I’m asserting at load time but there’s no reason it couldn’t do it before that.

compile time doesn’t make much sense. When you use a MonoBehaviour in Unity it is already compiled. I guess you mean a check at “edit time”. There’s not really a big difference between runtime and edit time. The main difference is that at edit time Start / Awake / Update isn’t called.

Depending on the purpose of your script you could use the ExecuteInEditMode attribute. However this can lead to strange and unwanted behaviour. ExecuteInEditMode should rarely be used and only if it’s really necessary.

The usual approach to provide an input check for your own classes during editing is to write a custom inspector for your class. When you use DrawDefaultInspector Unity will draw the usual inspector for your class, but you can do additional checks afterwards.

Instead of the DrawDefaultInspector you can of course provide your own GUI code.

Read the section about custom inspectors.