Version 3.3.0.1

Odin has a dedicated attribute overview with examples

DisableIfAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[DontApplyToListElements]
[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)]
[Conditional("UNITY_EDITOR")]
public sealed class DisableIfAttribute : Attribute, _Attribute

DisableIf is used on any property, and can disable or enable the property in the inspector.

Use this to disable properties when they are irrelevant.

Inheritance
  • System.Object
  • System.Attribute
  • DisableIfAttribute
Example

The following example shows how a property can be disabled by the state of a field.

public class MyComponent : MonoBehaviour
{
	public bool DisableProperty;

	[DisableIf("DisableProperty")]
	public int MyInt;

    public SomeEnum SomeEnumField;

	[DisableIf("SomeEnumField", SomeEnum.SomeEnumMember)]
	public string SomeString;
}
Example

The following examples show how a property can be disabled by a function.

public class MyComponent : MonoBehaviour
{
	[EnableIf("MyDisableFunction")]
	public int MyInt;

	private bool MyDisableFunction()
	{
		// ...
	}
}

Constructors

DisableIfAttribute(String)
Disables a property in the inspector, based on the value of a resolved string.
public DisableIfAttribute(string condition)
Parameters
System.String condition

A resolved string that defines the condition to check the value of, such as a member name or an expression.

DisableIfAttribute(String, Object)
Disables a property in the inspector, if the resolved string evaluates to the specified value.
public DisableIfAttribute(string condition, object optionalValue)
Parameters
System.String condition

A resolved string that defines the condition to check the value of, such as a member name or an expression.

System.Object optionalValue

Value to check against.

Fields

Condition
A resolved string that defines the condition to check the value of, such as a member name or an expression.
public string Condition
Value
The optional condition value.
public object Value