Version 3.3.1.2

Odin has a dedicated attribute overview with examples

HideIfAttribute 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)]
[DontApplyToListElements]
[Conditional("UNITY_EDITOR")]
public sealed class HideIfAttribute : Attribute, _Attribute

HideIf is used on any property and can hide the property in the inspector.

Use this to hide irrelevant properties based on the current state of the object.

Inheritance
  • System.Object
  • System.Attribute
  • HideIfAttribute
Example

This example shows a component with fields hidden by the state of another field.

public class MyComponent : MonoBehaviour
{
	public bool HideProperties;

	[HideIf("HideProperties")]
	public int MyInt;

	[HideIf("HideProperties", false)]
	public string MyString;

    public SomeEnum SomeEnumField;

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

This example shows a component with a field that is hidden when the game object is inactive.

public class MyComponent : MonoBehaviour
{
	[HideIf("MyVisibleFunction")]
	public int MyHideableField;

	private bool MyVisibleFunction()
	{
		return !this.gameObject.activeInHierarchy;
	}
}

Constructors

HideIfAttribute(String, Boolean)
Hides a property in the inspector, based on the value of a resolved string.
public HideIfAttribute(string condition, bool animate = true)
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.Boolean animate

Whether or not to slide the property in and out when the state changes.

HideIfAttribute(String, Object, Boolean)
Hides a property in the inspector, if the resolved string evaluates to the specified value.
public HideIfAttribute(string condition, object optionalValue, bool animate = true)
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.

System.Boolean animate

Whether or not to slide the property in and out when the state changes.

Fields

Animate
Whether or not to slide the property in and out when the state changes.
public bool Animate
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