Class HideIfAttribute
Conditionally hides a serialized field in the Unity Inspector based on the current value of another field on the same object.
Inherited Members
Namespace: Scylla.Core.Attributes
Assembly: ScyllaCore.dll
Syntax
[AttributeUsage(AttributeTargets.Field)]
public sealed class HideIfAttribute : ConditionalAttributeBase
Remarks
When the condition evaluates to true, the decorated field is
completely removed from view in the Inspector. The field's value is
preserved in memory and serialization; only the visual representation
is suppressed.
This is the inverse of ShowIfAttribute. Use HideIfAttribute when a field becomes irrelevant under certain conditions and clutters the Inspector unnecessarily (e.g., hiding projectile settings when a weapon is set to melee mode, or hiding hint toggles when the difficulty is set to its hardest level).
Unlike DisableIfAttribute, which grays out but preserves
the field's visibility, this attribute removes the field entirely from the
Inspector layout. Prefer HideIf when there is no value in showing
the field in its current context.
The condition field must be serialized and accessible from the same object. The attribute supports the following field types for condition evaluation:
bool- truthy whentrueint- truthy when non-zerofloat- truthy when non-zerostring- truthy when non-null and non-emptyenum- truthy when the value is not the first enum member (index 0)- Object reference - truthy when the reference is not
null
Use nameof() for the condition field name to get a compile-time-safe
string that refactoring tools can update automatically.
public class Settings : MonoBehaviour
{
[SerializeField] private bool _isAdvancedMode;
/* Hide the simple option when advanced mode is active */
[HideIf(nameof(_isAdvancedMode))]
[SerializeField] private string _simpleOption;
[SerializeField] private Difficulty _difficulty;
/* Hide easy-mode hint toggle when playing on Hard */
[HideIf(nameof(_difficulty), Difficulty.Hard)]
[SerializeField] private bool _showHints = true;
/* Hide the explosion effect unless damage exceeds a threshold */
[HideIf(nameof(_damage), 100, CompareOperator.LessThan)]
[SerializeField] private ParticleSystem _explosionEffect;
[SerializeField] private int _damage = 25;
}
Constructors
HideIfAttribute(string)
Hides the decorated field when the specified condition field evaluates to a truthy value.
Declaration
public HideIfAttribute(string conditionField)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field whose value controls whether this field is
hidden. Use |
Remarks
Truthiness is determined by the field type: true for booleans,
non-zero for numeric types, non-null and non-empty for strings, non-null for
object references, and non-zero index for enums. This overload does not
perform an explicit value comparison - it evaluates the field as a boolean
condition directly.
HideIfAttribute(string, object)
Hides the decorated field when the specified condition field equals the given comparison value.
Declaration
public HideIfAttribute(string conditionField, object compareValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field whose value controls whether this field is
hidden. Use |
| object | compareValue | The value to compare against the condition field. Supports |
Remarks
The comparison uses Equals by default.
The compareValue is compared against the condition
field's value using type-appropriate equality: boolean equality for
bool fields, Mathf.Approximately for float fields,
ordinal string comparison for string fields, and integer index
comparison for enum fields.
HideIfAttribute(string, object, CompareOperator)
Hides the decorated field when the condition field's value satisfies the given comparison operator relative to the comparison value.
Declaration
public HideIfAttribute(string conditionField, object compareValue, CompareOperator op)
Parameters
| Type | Name | Description |
|---|---|---|
| string | conditionField | The name of the serialized field whose value controls whether this field is
hidden. Use |
| object | compareValue | The value to compare against the condition field. Must be compatible with
the chosen |
| CompareOperator | op | The CompareOperator used to evaluate the condition. Determines
how the condition field's value is compared against |
Remarks
Use this overload when a simple equality check is insufficient. For example, hide a field when a numeric value falls below a minimum threshold, or when a flags enum contains a specific combination of bits.
Ordered comparisons (LessThan,
GreaterThan, etc.) are supported for
int and float fields only. Bitwise AND comparison
(BitwiseAnd) is supported for int
and enum (flags) fields.