Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never suggest to make fields readonly if they are marked with SerializeField #419

Closed
SugoiDev opened this issue Mar 7, 2018 · 4 comments
Milestone

Comments

@SugoiDev
Copy link

SugoiDev commented Mar 7, 2018

Unity doesn't like readonly fields in serialization, so when a field is marked with the SerializeFieldAttribute, the suggestion to "Field can be made readonly" should be suppressed, since it will cause that field to silently no longer be serialized by Unity.

Related issues #291 and #25

screenshot 2018 03 07-03 03 15

@citizenmatt
Copy link
Member

This only happens in classes that are not Unity based, e.g. not derived from MonoBehaviour. This is because we don't mark any fields, even those with attributes, as implicitly used unless they are in a Unity class.

Behaviour should be:

  • If the custom class has a [Serializable] attribute, handle all fields as though they're on a MonoBehaviour. I.e. public fields or those marked with [SerializeField] are implicitly used, [NotSerialized] disables this. Highlight the fields as Unity fields (gutter icon)
  • If a class does not have the [Serializable] attribute, highlight usages of [SerializeField]. I think it should be a redundant highlight - the attribute does nothing, so grey it out. Quick fix to remove, another to add [Serializable] to the class. (Alternatives would be hint or suggestion on the attribute to require [Serializable] on the class, as this is clearly the intention)

@citizenmatt citizenmatt added this to the Rider 2018.2 milestone Apr 6, 2018
@julia-vaseva
Copy link

@citizenmatt
Copy link
Member

see also RIDER-9341

@fuj1n
Copy link

fuj1n commented Aug 13, 2023

Getting this in Rider 2023.2 with JetBrains Rider Editor 3.0.24

Seems like inherited Serializable attributes aren't considered in the above-mentioned fix.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants