# Attributes ### What are attributes? Attributes are ***"markers"*** or ***"tags"*** for associating metadata with code in a declarative way. They can be used to tell the Unity Editor, C# compiler, or even our own scripts how to treat certain ***classes***, ***fields***, ***methods***, and so on.
[https://docs.unity3d.com/Manual/Attributes.html](https://docs.unity3d.com/Manual/Attributes.html)
Attributes are declared right before their target and are always wrapped in brackets: ```c# using JetBrains.Annotations; using System.Runtime.CompilerServices; using UdonSharp; using UnityEngine; using UnityEngine.Serialization; using Varneon.VUdon.Editors; using Varneon.VUdon.Noclip.Abstract; using Varneon.VUdon.Noclip.Enums; using VRC.SDKBase; using VRC.Udon.Common; [assembly: InternalsVisibleTo("Varneon.VUdon.Noclip.Editor")] namespace Varneon.VUdon.Noclip { [SelectionBase] [DefaultExecutionOrder(-1000000000)] [AddComponentMenu("VUdon/Noclip")] [DisallowMultipleComponent] [HelpURL("https://github.com/Varneon/VUdon-Noclip/wiki/Settings")] [UdonBehaviourSyncMode(BehaviourSyncMode.None)] public partial class Noclip : UdonSharpBehaviour { [FoldoutHeader("Options", "Options that can be edited before build and in-game")] [SerializeField] [Tooltip("Method for triggering the noclip mode")] private NoclipTriggerMethod noclipTriggerMethod = NoclipTriggerMethod.DoubleJump; [SerializeField] [FieldLabel("Toggle Threshold (s)")] [Tooltip("Time in which jump has to be double tapped in order to toggle noclip")] [FieldRange(0.1f, 1f)] private float toggleThreshold = 0.25f; [SerializeField] [FieldLabel("Speed (m/s)")] [Tooltip("Maximum speed in m/s")] [Min(1f)] [FormerlySerializedAs("velocity")] private float speed = 15f; [PublicAPI("Sets noclip enabled")] public void _SetNoclipEnabled(bool enabled) { SetNoclipEnabled(enabled); } #if UNITY_EDITOR && !COMPILER_UDONSHARP [UsedImplicitly] [UnityEditor.Callbacks.PostProcessScene(-1)] private static void InitializeOnBuild() { } #endif } } ``` --- ### What attributes should I know about? There are several quality of life attributes that everyone should know and use, and here are most of them: #### Field Attributes These attributes can be used on fields, primarily to alter their appearance in the inspector.[\[Range\]](https://docs.unity3d.com/ScriptReference/RangeAttribute.html "https://docs.unity3d.com/ScriptReference/RangeAttribute.html") | Restrict a float or int variable to a specific range |
[\[Min\]](https://docs.unity3d.com/ScriptReference/MinAttribute.html "https://docs.unity3d.com/ScriptReference/MinAttribute.html") | Restrict a float or int variable to a specific minimum value |
[\[Header\]](https://docs.unity3d.com/ScriptReference/HeaderAttribute.html "https://docs.unity3d.com/ScriptReference/HeaderAttribute.html") | Add a space and a header above a field in inspector |
[\[TextArea\]](https://docs.unity3d.com/ScriptReference/TextAreaAttribute.html "https://docs.unity3d.com/ScriptReference/TextAreaAttribute.html") | Make string field height-flexible and scrollable |
[\[ColorUsage\]](https://docs.unity3d.com/ScriptReference/ColorUsageAttribute.html "https://docs.unity3d.com/ScriptReference/ColorUsageAttribute.html") | Configure Color field to support HDR and/or alpha |
[\[GradientUsage\]](https://docs.unity3d.com/ScriptReference/GradientUsageAttribute.html "https://docs.unity3d.com/ScriptReference/GradientUsageAttribute.html") | Configure Gradient field's color space and HDR |
[\[Space\]](https://docs.unity3d.com/ScriptReference/SpaceAttribute.html "https://docs.unity3d.com/ScriptReference/SpaceAttribute.html") | Add a space above a field in inspector |
[\[SerializeField\]](https://docs.unity3d.com/ScriptReference/SerializeField.html "https://docs.unity3d.com/ScriptReference/SerializeField.html") | Force Unity to serialize a private field |
[\[HideInInspector\]](https://docs.unity3d.com/ScriptReference/HideInInspector.html "https://docs.unity3d.com/ScriptReference/HideInInspector.html") | Hide a variable from the inspector |
[\[Tooltip\]](https://docs.unity3d.com/ScriptReference/TooltipAttribute.html "https://docs.unity3d.com/ScriptReference/TooltipAttribute.html") | Display a text in inspector when hovering over a field |
[\[NonSerialized\]](https://docs.unity3d.com/ScriptReference/NonSerialized.html "https://docs.unity3d.com/ScriptReference/NonSerialized.html") | Prevent variable from being serialized (also hides from inspector) |
[\[NonReorderable\]](https://docs.unity3d.com/ScriptReference/NonReorderableAttribute.html "https://docs.unity3d.com/ScriptReference/NonReorderableAttribute.html") | Disable default reorderability in new array and list fields ***(Unity 2020.2+)*** |
[\[FormerlySerializedAs\]](https://docs.unity3d.com/ScriptReference/Serialization.FormerlySerializedAsAttribute.html "https://docs.unity3d.com/ScriptReference/Serialization.FormerlySerializedAsAttribute.html") | Preserve original serialized value of a field when renaming it |
[\[UdonBehaviourSyncMode\]](https://udonsharp.docs.vrchat.com/udonsharp#udonbehavioursyncmode "https://udonsharp.docs.vrchat.com/udonsharp#udonbehavioursyncmode") | Enforce a synchronization mode of an UdonSharpBehaviour |
[\[DefaultExecutionOrder\]](https://udonsharp.docs.vrchat.com/udonsharp#defaultexecutionorder "https://udonsharp.docs.vrchat.com/udonsharp#defaultexecutionorder") | Specify the execution order of update loops in relation to other UdonSharpBehaviours |
[\[RequireComponent\]](https://docs.unity3d.com/ScriptReference/RequireComponent.html "https://docs.unity3d.com/ScriptReference/RequireComponent.html") | Add a component automatically to the same object and prevent its removal |
[\[DisallowMultipleComponent\]](https://docs.unity3d.com/ScriptReference/DisallowMultipleComponent.html "https://docs.unity3d.com/ScriptReference/DisallowMultipleComponent.html") | Prevent multiple instances of the component from being added to the same object |
[\[AddComponent\]](https://docs.unity3d.com/ScriptReference/AddComponentMenu.html "https://docs.unity3d.com/ScriptReference/AddComponentMenu.html") | Specify the path to this component in the "Add Component" menu |
[\[ExcludeFromPreset\]](https://docs.unity3d.com/ScriptReference/ExcludeFromPresetAttribute.html "https://docs.unity3d.com/ScriptReference/ExcludeFromPresetAttribute.html") | Prevent creation of presets from instances of the class |
[\[SelectionBase\]](https://docs.unity3d.com/ScriptReference/SelectionBaseAttribute.html "https://docs.unity3d.com/ScriptReference/SelectionBaseAttribute.html") | Mark the GameObject as a selection base object for Scene View picking |
[\[Icon\]](https://docs.unity3d.com/ScriptReference/IconAttribute.html "https://docs.unity3d.com/ScriptReference/IconAttribute.html") | Specify an icon for a MonoBehaviour or ScriptableObject ***(Unity 2021.3+)*** |
[\[ContextMenu\]](https://docs.unity3d.com/ScriptReference/ContextMenu.html "https://docs.unity3d.com/ScriptReference/ContextMenu.html") | Add a command to the Component's context menu |
[\[Obsolete\]](https://learn.microsoft.com/en-us/dotnet/api/system.obsoleteattribute?view=net-7.0 "https://learn.microsoft.com/en-us/dotnet/api/system.obsoleteattribute?view=net-7.0") | Mark an element to be no longer in use |
[\[PublicAPI\]](https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#PublicAPIAttribute "https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#PublicAPIAttribute") | Mark publicly available API which should not be removed and treated as used |
[\[UsedImplicitly\]](https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#UsedImplicitlyAttribute "https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#UsedImplicitlyAttribute") | Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library) |
[\[NotNull\]](https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#NotNullAttribute "https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#NotNullAttribute") | Indicates that the value of the marked element can never be null |
[\[CanBeNull\]](https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#CanBeNullAttribute "https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html#CanBeNullAttribute") | Indicates that the value of the marked element could be null sometimes |
Example of this attribute being used: [Udonity's AssemblyInfo.cs](https://github.com/Varneon/VUdon-Udonity/blob/main/Packages/com.varneon.vudon.udonity/Runtime/AssemblyInfo.cs "https://github.com/Varneon/VUdon-Udonity/blob/main/Packages/com.varneon.vudon.udonity/Runtime/AssemblyInfo.cs")
1. Create a new C# file called `AssemblyInfo.cs` into your Runtime folder 2. Add the following content inside the file: ```c# using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("YOUR_EDITOR_ASSEMBLY_NAME_HERE")] ``` --- ##### [\[CreateAssetMenu\]](https://docs.unity3d.com/ScriptReference/CreateAssetMenuAttribute.html "https://docs.unity3d.com/ScriptReference/CreateAssetMenuAttribute.html") Mark a [ScriptableObject](https://docs.unity3d.com/ScriptReference/ScriptableObject.html "https://docs.unity3d.com/ScriptReference/ScriptableObject.html")-derived type to be automatically listed in the Assets/Create submenu. Learn more about ScriptableObjects [here](https://vrclibrary.com/wiki/books/varneons-unity-development-handbook/page/scriptable-objects "https://vrclibrary.com/wiki/books/varneons-unity-development-handbook/page/scriptable-objects"). ```c# // menuName: Path to the menu item // fileName: Default name of the new file // order: Priority of the menu item (100 is often reasonble) [CreateAssetMenu(menuName = "VUdon - Vehicles/Data Presets/Car Spec Sheet", fileName = "NewCarSpecSheet.asset", order = 100)] public class CarSpecSheet : ScriptableObject { } ``` --- ##### [\[InspectorName\]](https://docs.unity3d.com/ScriptReference/InspectorNameAttribute.html "https://docs.unity3d.com/ScriptReference/InspectorNameAttribute.html") Use this attribute on enum value declarations to change the display name shown in the Inspector. ```c# public enum ColorDisplayMode { [InspectorName("RGB 0-255")] RGB255, [InspectorName("RGB 0-1.0")] RGB1, HSV } ```