Clamping variable values in the editor

Let’s say I have a float, but I only want to be able to enter values between 0 and 1. This kind of clamping works for certain variables of Unity-created objects. Can we do it for our own scripts?

I believe what you are looking for is OnValidate() (undocumented currently, so it may change). You could clamp settings here.

	void OnValidate()
	{
		transform.rotation = Quaternion.identity;
		subdivisions.x = Mathf.Max( 1, Mathf.Floor( subdivisions.x ) );
		subdivisions.y = Mathf.Max( 1, Mathf.Floor( subdivisions.y ) );
		subdivisions.z = Mathf.Max( 1, Mathf.Floor( subdivisions.z ) );
	}

If you are looking for something more robust, then you may just want to have a custom editor: