unity3d Attributes Common inspector attributes


Example

[Header( "My variables" )]
public string MyString;

[HideInInspector]
public string MyHiddenString;

[Multiline( 5 )]
public string MyMultilineString;

[TextArea( 2, 8 )]
public string MyTextArea;

[Space( 15 )]
public int MyInt;

[Range( 2.5f, 12.5f )]
public float MyFloat;

[Tooltip( "This is a tip for MyDouble" )]
public double MyDouble;

[SerializeField]
private double myHiddenDouble;

Result

When hovering over the label of a field:

Result2


[Header( "My variables" )]
public string MyString;

Header places a bold label containing the text above the attributed field. This is often used for labeling groups to make them stand out against other labels.

[HideInInspector]
public string MyHiddenString;

HideInInspector prevents public fieldsfrom being shown in the inspector. This is useful for accessing fields from other parts of code where they aren't otherwise visible or mutable.

[Multiline( 5 )]
public string MyMultilineString;

Multiline creates a textbox with a specified number of lines. Exceeding this amount will neither expand the box nor wrap the text.

[TextArea( 2, 8 )]
public string MyTextArea;

TextArea allows multiline-style text with automatic word-wrapping and scroll bars if the text exceeds the allotted area.

[Space( 15 )]
public int MyInt;

Space forces the inspector to add extra space between previous and current items -useful in distinguishing and separating groups.

[Range( 2.5f, 12.5f )]
public float MyFloat;

Range forces a numerical value between a minimum and a maximum. This attribute also works on integers and doubles, even though min and max are specified as floats.

[Tooltip( "This is a tip for MyDouble" )]
public double MyDouble;

Tooltip shows an additional description whenever the field's label is hovered over.

[SerializeField]
private double myHiddenDouble;

SerializeField forces Unity to serialize the field - useful for private fields.