Check if public field set in editor at compilation

Can I add functionality similar to [RequireComponent] to my public fields? So if public variable not set it cause compilation error.

Thanks!

Hi, I don’t think you can do that at compile time but here is how I would do it:
You can use the OnValidate callback: Unity - Scripting API: MonoBehaviour.OnValidate()

In the OnValidate function, you can check the value of a field or use GetComponent to check if a component is present. In case of error, you can warn the user with a LogError.

OnValidate is called in the editor any time a value is changed or when the object/scene is loaded or reloaded (after each re-compilation for example) so it’s very convenient for this kind of check.

Check if it is not null in Start() method