Version 2.1.0.0

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)]
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.

Fields

MinValue
The minimum value for the property.
public double MinValue

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.