Search Issue Tracker

Active

Planned for 2019.4, 2020.1

Votes

170

Found in

2018.3.0a1

2018.3.0b1

Issue ID

1080427

Regression

Yes

[SerializedField] fields produce "Field is never assigned to..." warning

Scripting

-

1. Open the attached project (warning.zip)
2. Observe the warning in the console

Expected: field with SerializeField attribute do not produce the warning

Reproduced in 2018.3.0a1, 2018.3.0b1, 2018.3.0b2, 2019.1.0a1
Did not reproduce in 2018.2.8f1
Regression introduced in 2018.3.0a1

  1. Response avatar

    lukaszunity

    Nov 06, 2019

    #pragma warning disable 0649
    // your code
    #pragma warning restore 0649

    Or disable it globally by adding a file named csc.rsp to the root of you Assets folder, e.g. Assets/csc.rsp, with the following contents without quotes.

    /nowarn:0649

    This will tell the C# compiler to not emit a warning for CS0649 / unused fields.

    If you have .asmdefs with csc.rsp in your project, then you also need to add the "/nowarn:0649" line to those csc.rsp files.

Comments (77)

  1. 03b5422b519c51eb98f03f25678712d8?d=mm

    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.

  2. D9105352c7a09434ff8fb69b76eb1ad9?d=mm

    Xavier78

    Feb 20, 2019 08:41

    Why has this not been fixed yet?

  3. D998d5758d57fa06af2b545cf804fca0?d=mm

    qpanzmbrainz

    Feb 14, 2019 22:23

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

  4. F9440774552a4e4217bc66136867b935?d=mm

    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.

  5. 42b11a402b6a4c0e2afc8a73172580f9?d=mm

    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.

  6. 32a15ee3ebf22c352625bb838c7a8b2a?d=mm

    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.

  7. C35b9264646fd1b72f6ccfca2622c409?d=mm

    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!

  8. 15ff0e0aad9c52ef49fd13d7312e2219?d=mm

    Node

    Jan 19, 2019 11:00

    i agree. if this is by design, then the design should be fixed. because the current design either forces you to make everything public which violates the most basic OOP principles, or just live with warnings and hope that you don't miss any actual useful warning within the spam of useless ones. disabling them in every file that has serialized fields is ridiculous.

    this is definitely a design flaw and should be fixed. i just hope someone notices this within a resolved issue...

  9. E440a070914148a6bc803878c27fdcad?d=mm

    mikedg1

    Jan 01, 2019 12:42

    If this is by design, then the design has a bug, where do we submit reports for that?

  10. 022c156d76ef8c3212a324c252fa9fbe?d=mm

    MechEthan

    Dec 19, 2018 17:41

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.