Odin has a dedicated attribute overview with examples

ValidateInputAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = true, Inherited = true)]
public sealed class ValidateInputAttribute : Attribute, _Attribute

ValidateInput is used on any property, and allows to validate input from inspector.

Use this to enforce correct values.

  • System.Object
  • System.Attribute
  • ValidateInputAttribute


ValidateInput refuses invalid values.


ValidateInput only works in the editor. Values changed through scripting will not be validated.


The following examples shows how a speed value can be forced to be above 0.

public class MyComponent : MonoBehaviour
	public float Speed;

	// Specify custom output message and message type.
	[ValidateInput("ValidateInput", "Health must be more than 0!", InfoMessageType.Warning)]
	public float Health;

	private bool ValidateInput(float property)
		return property > 0f;

The following example shows how a static function could also be used.

public class MyComponent : MonoBehaviour
	public int MyInt;

	private static bool StaticValidateFunction(int property)
		return property != 0;


ValidateInputAttribute(String, String, InfoMessageType)
Initializes a new instance of the ValidateInputAttribute class.
public ValidateInputAttribute(string memberName, string defaultMessage = null, InfoMessageType messageType = InfoMessageType.Error)
System.String memberName

Name of callback function to validate input. The function must have at least one parameter of the same type as the property.

System.String defaultMessage

Default message for invalid values.

InfoMessageType messageType

Type of the message.


If true, the validation method will not only be executed when the User has changed the value. It'll run once every frame in the inspector.
public bool ContinuousValidationCheck
Default message for invalid values.
public string DefaultMessage
Whether to also trigger validation when changes to child values happen. This is true by default.
public bool IncludeChildren
Name of callback function to validate input. The function must have at least one parameter of the same type as the property.
public string MemberName
The type of the message.
public InfoMessageType MessageType