Attributes in Unity 2020

Needone App
2 min readJun 25, 2020

[HideInInspector]

If you need a public variable in your script (so the other scripts can use this variable), but you don’t want it exposed to inspector. See below example, the public hidenProperty it not visible in the inspector.

HideInInspector in Unity

[Header(“string”)]

Add a comment in the inspector for the variables used in the script. This is especially useful when you have tons of variables. See below example: two attributes, speed and myBag have their comments above in the inspector:

[Header] in Unity

[SerializeField]

On the opposite of the [HideInInspector], [SerializeField] makes a private variable of a script visible in the inspector.

SerializeField in Unity

[Space]

Make a space in the inspector, to organize the attributes and variables in the inspector:

Space in Unity

[Range]

Every time when we create int, float varibles, it would be better to put a range on it. As in some scenarios, it is not just us put the value here, there are might be some other people, such as testers (testers are friends 😎) want to play with different value and we don't want them to put some crazy value. i.e speed, weight, attack and etc. See following example of variable Speed:

Range in Unity

Reference:

Originally published at https://needone.app on June 25, 2020.

--

--