Version 3.3.1.2

Odin has a dedicated attribute overview with examples

MaxValueAttribute 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 MaxValueAttribute : Attribute, _Attribute

MaxValue is used on primitive fields. It caps value of the field to a maximum value.

Use this to define a maximum value for the field.

Inheritance
  • System.Object
  • System.Attribute
  • MaxValueAttribute
Remarks

note

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

Example

The following example shows a component where a speed value must be less than or equal to 200.

public class Car : MonoBehaviour
{
	// The speed of the car must be less than or equal to 200.
	[MaxValue(200)]
	public float Speed;
}
Example

The following example shows how MaxValue can be combined with MinValueAttribute.

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

Constructors

MaxValueAttribute(Double)
Sets a maximum value for the property in the inspector.
public MaxValueAttribute(double maxValue)
Parameters
System.Double maxValue

The max value.

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

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

Fields

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