Version 3.3.0.1

Odin has a dedicated attribute overview with examples

MinValueAttribute 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 = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class MinValueAttribute : Attribute, _Attribute

MinValue is used on primitive fields. It caps value of the field to a minimum value.

Use this to define a minimum value for the field.

Inheritance
  • System.Object
  • System.Attribute
  • MinValueAttribute
Remarks

note

Note that this attribute only works in the editor! Values changed from scripting will not be capped at a minimum.

Example

The following example shows a player component that must have at least 1 life.

public class Player : MonoBehaviour
{
	// The life value must be set to at least 1.
	[MinValue(1)]
	public int Life;
}
Example

The following example shows how MinValue can be combined with MaxValueAttribute

public class Health : MonoBehaviour
{
	// The health value must be between 0 and 100.
	[MinValue(0), MaxValue(100)]
	public float Health;
}

Constructors

MinValueAttribute(Double)
Sets a minimum value for the property in the inspector.
public MinValueAttribute(double minValue)
Parameters
System.Double minValue

The minimum value.

MinValueAttribute(String)
Sets a minimum value for the property in the inspector.
public MinValueAttribute(string expression)
Parameters
System.String expression

The string with which to resolve a minimum value. This could be a field, property or method name, or an expression.

Fields

Expression
The string with which to resolve a minimum value. This could be a field, property or method name, or an expression.
public string Expression
MinValue
The minimum value for the property.
public double MinValue