⬜️ Unity - Attributes
Attributes
Updated at 2016-10-30 09:41
A quick overview of all the class/method/field attributes Unity has.
Components
HelpURLAttributeset a custom URL for documentation.DisallowMultipleComponentprevents multiple instances of this component in a game object.RequireComponentthis component requires another component to be present in the game object.SelectionBaseAttributedefines which object will be picked when selected in the scene view.
Component Fields
HideInInspectorhide the field from inspector.SerializeFieldserialize the field, makes non-publicfields visible.TooltipAttributeset help text on field mouse-over.SpaceAttributeadd spacing between fields.HeaderAttributeadd heading text above fields.DelayedAttributethis field is not updated until user presses enter or removes focus.RangeAttributerestrictint/floatto be in the specified range.MultilineAttributechange string field to multiline textbox.TextAreaAttributechange string field to flexible text area.ColorUsageAttributeconfigure color field's color picker settings.
Menus
AddComponentMenuadd custom script in specified Add Component menu.ContextMenuadd this method in context menu of the component.ContextMenuItemAttributeadd a method under context menu of this field.CreateAssetMenuAttributeadd this scriptable object under Assets/Create.MenuItemadd a method to the editor main menu.PreferenceItemadd preference section to Preferences window.
Rendering
ImageEffectOpaquemake image effect to be rendered after opaque geometry.ImageEffectAllowedInSceneViewmake image effect to be rendered into scene view cameraImageEffectTransformsToLDRswitch image effect to LDR rendering.
Runtime
RuntimeInitializeOnLoadMethodAttributeautomatically call a static function after a runtime scene has been loaded.SharedBetweenAnimatorsAttributemakes that thisStateMachineBehaviouris only initialized once and shared between all animators.
Editor
InitializeOnLoadAttributeautomatically initialize a class after editor launches.InitializeOnLoadMethodAttributeautomatically call a static function after editor launches.DidReloadScriptsautomatically call a static function after scripts have been reloaded.ExecuteInEditModemake a script execute even when not in play mode.DrawGizmoAttributeadd gizmo icon for this component type.GUITargetAttributecontrols to which display isOnGUIUI rendered.OnOpenAssetAttributeallow overriding what Unity does when you open an asset.
Custom Editors
CustomPropertyDrawerspecifies which runtime class this drawer is for.CustomEditorspecifies which runtime class this custom editor is for.CanEditMultipleObjectsallows multi-object editing for this custom editor.CustomPreviewAttributeallow adding custom preview for containing game object.
Building
PreserveAttributeprevents a class, method or field from being stripped if build code stripping is enabled.PostProcessSceneAttributeautomatically call a static function after each scene build.PostProcessBuildAttributeautomatically call a static function after whole build.