Version 2.1.0.0

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]
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, if the specified member returns true.
public HideIfAttribute(string memberName, bool animate = true)
Parameters
System.String memberName

Name of a bool field, property or function to show or hide the property.

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 specified member returns the specified value.
public HideIfAttribute(string memberName, object optionalValue, bool animate = true)
Parameters
System.String memberName

Name of member to check the value of.

System.Object optionalValue

The value to check for.

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
MemberName
Name of a bool field, property or function to show or hide the property.
public string MemberName
Value
The optional member value.
public object Value