Skip to content

Attribute is redundant when applied to this declaration type

Matt Ellis edited this page Mar 26, 2018 · 1 revision

Unity ships with a number of attributes, such as SerializeField, CustomEditor, ExecuteInEditMode and more that do not provide any AttributeTargets. Technically, these attributes can be applied to any declaration - class, method, field, property and so on, and the code will still compile. However, these attributes are only used when applied to a specific target declaration, and are silently ignored on other declaration types.

For example, it can be a fairly common mistake to apply the SerializeField attribute to a property - this will not do anything, and the mistake will only be discovered at runtime, if at all.

This inspection will highlight these attributes as dead code when they are applied to an incorrect target type, with an Alt+Enter quick fix to remove redundant attributes.

Clone this wiki locally