Skip to content

Unity attributes: a practical guide

↑
Unity 6

C# attributes are metadata written in square brackets, such as [SerializeField]. Unity reads many of them to decide how to show fields, register components, initialize code or compile jobs. They do not replace validation, clear dependencies or performance measurements.

  1. Decide whether you need to affect saved data, the Inspector UI, a component, the Editor, or a job.
  2. Check the attribute’s target, namespace and optional package requirements.
  3. Copy an example and test it with a real scene or prefab.
  4. Also test a player build when using Editor APIs or conditional compilation.

A frequent source of confusion is the difference between an attribute affecting the Editor and an actual runtime guarantee. A [Range] slider does not validate network input, and a hidden field can still be serialized.

The five guides are based on Unity’s official scripting API documentation, with original explanations and practical examples.

Unity Scripting API