Comments (70)

roberto_sc

Apr 11, 2019 05:52

This is not a good solution.

Lyje

Apr 07, 2019 11:58

@Xavier78 I strongly disagree. In my view it's almost always bad practice to assign to [SerializeField] fields from code. These fields are for data to be injected by Unity and in most cases should be essentially immutable from the code's perspective.

Given this - which is of course an opinion, but one that has served me very well - the warning actively discourages good practice.

Xavier78

Mar 21, 2019 02:09

Okay so I have been dealing with this for a while. The warning should still be there, and this is why. If a private field has a property, or gets assigned to from a public method, this warning will go away. If a private serialized field doesn't have one of those two things then it is bad. Clearly that variable needs to be assigned to by hand since you are showing it to the editor, so there should be a way to assign to it from code side as well. I would suggest if you don't want to use prop, then use a Setup() method that has all serialized fields assigned to, which will make your code more suitable for unit testing in the future. I sincerely hope they do not get rid of this warning for [SerializedFeilds] as that would make wrong coding practices accepted.

azuredown

Mar 05, 2019 18:27

So Unity's just going to wait for the compiler to fix it? Pretty disappointing considering JetBrains fixed this problem in Rider a long time ago.

Xavier78

Feb 20, 2019 08:41

Why has this not been fixed yet?

qpanzmbrainz

Feb 14, 2019 22:23

This is fixed for .Net 3.5, but is not fixed for .Net 4.X

Lyje

Feb 09, 2019 13:51

Labelling this as "by design" is, frankly, absurd. It actively opposes the purpose of warnings. In this case a warning is issued when the programmer uses good practice, thus discouraging it. Warnings are designed specifically to discourage bad practices.

SpencerMowrey

Feb 01, 2019 06:40

Boo bad design. Not sure why this could slip through. I guess we want newer Roslyn and this is what we get. Honestly this is a long standing issue that Unity should address in an alternative way. On compile complete if warning cs0649 is field SerializedField... yes? Don't show the stinking warning! Why rely and wait on Roslyn to get fixed? You have control over what is displayed in the console.

potato_based_username

Jan 25, 2019 23:30

If this is by design, then your design is terrible and you should be ashamed of it.

AlanMattano

Jan 24, 2019 17:01

I wish to vote for this issue or at least a C# video tutorial in the learning section explaining how to declare my variables now!