FieldConditionAttribute - Metimos/com.metimos.utilities GitHub Wiki

An attribute that can be used to conditionally show or hide a field in the inspector.

Passing the third parameter as false will completely hide the field instead of disabling it.

FieldCondition(string name, object value, bool visible = true)
Parameter Description
name Which property or field to compare with - must be within the same scope of the attribute's field.
value The value to compare with the property or field.
visible Whether the field should remain visible, otherwise it will be disabled (greyed out).



public void Example : MonoBehaviour
    private bool _showField = true;

    // Will be active when _showField is true.
    [FieldCondition(nameof(_showField), true)]
    private int _onField = 0;

    // Will be active when _showField is false.
    [FieldCondition(nameof(_showField), false)]
    private int _offField = 0;