Skip to content

Redundant FormerlySerializedAs attribute

Matt Ellis edited this page Feb 19, 2019 · 3 revisions

The [FormerlySerializedAs] attribute is used to tell Unity that a field has been previously serialised with a different name, to allow for versioning and renaming code.

This inspection will highlight redundant usages of the attribute, and provides an Alt+Enter quick fix to remove the redundant attribute. The attribute usage is considered redundant if:

  • It is applied to a field that is not serialised. This can be because the field is declared in a non-Unity type (e.g. does not derive from MonoBehaviour) or because the field is not serialised (e.g. private or marked with [NonSerialized]).
  • The previous name specified in the attribute arguments is the same as the current name of the field. E.g.:
    // Marked as redundant as the names are the same
    [FormerlySerializedAs("position")]
    public int position;

See the documentation for FormerlySerializedAsAttribute and also the Unity blog post announcing the feature.

This inspection was first added in Rider/ReSharper 2018.2.

Clone this wiki locally