Search Issue Tracker

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

Postponed

Votes

21

Found in

2018.3.0a1

2018.3.0b1

Issue ID

1080427

Regression

Yes

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

Mono

-

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.

  1. Response avatar

    Resolution Note (fix version ):

    This can be fixed using DiagnosticSuppressor API in Roslyn. However, this requires that Unity updates Roslyn to a newer version that supports DiagnosticSuppressor and that proper support for using Roslyn analyzers is added to Unity. The fix of this issue is therefore postponed.

    The new C# compiler is correct in reporting the additional warnings.

    You can disable the warnings with pragmas:

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

    Or disable it globally by adding a csc.rsp file to your project and adding command line switch to disable the warning.

Comments (61)

  1. Bd8ae845fd68eef42682d25b6e516e0a?d=mm

    domFC

    Sep 17, 2019 19:18

    This makes it really hard to see real warnings. Please fix this.

  2. 8dd865676b3397338a01a5b4b71383c8?d=mm

    F-N

    Sep 11, 2019 07:32

    Poor design. Really Unity, just fix this...

  3. 12f8b1d899b95dbcab59e7eade28a119?d=mm

    GrandBOOM

    Aug 29, 2019 15:35

    Please fix this. Yeah its "by desing" but that design in god damn horrible. Its making it harder to see actual warnings.

  4. 09b5416e1126419cc9ffd789e6ba2d5f?d=mm

    as3mbus

    Aug 26, 2019 08:27

    i'd love to see better explained resolution please.

    `Or disable it globally by adding a csc.rsp file to your project and adding command line switch to disable the warning. `

    how could you do that ?

  5. B7f76d6e75f42c076a38c723d8886964?d=mm

    VDraks

    Aug 13, 2019 19:06

    Please reopen issue

  6. 152dddd9c528d451a1df8d446e76a250?d=mm

    Simpowitch

    Aug 12, 2019 14:24

    This is litterally the worst resolvement of an issue I've seen. This is an issue and is spamming the console window when it absolutely shouldn't. I would like you to re-open this issue. Pure annoyance.

  7. 41ee2402153fef1ac3f29b178fd7edc4?d=mm

    RKOvlesen

    Aug 09, 2019 06:56

    I do not agree with this solution!

    SerializeField is am important tool to prevent public variables in scripts.
    Having to initialize every SerializeField variable to a default value as a workaround is redundant work, reduces readability and can cause confusion.

  8. 8382b669e96e7229ef2670c5f253f619?d=mm

    Bip901

    Jul 26, 2019 17:05

    So now when we're properly using one of Unity's features in the documented, recommended way, we have to either include a #suppress and #restore in EVERY CLASS (which is what I've done for my ~70 classes), or manually assign the default value to every field? That is unacceptable!

    Apart for the warning, when using the [SerializeField] private pattern on fields only changed from the inspector, I get a message stating I should make the field readonly - though making it readonly prevents it from being serialized!

  9. 8c8da715f0d83eb809169082e896dd61?d=mm

    Goat-Boy

    Jul 22, 2019 19:34

    Whenever my project builds I get 40 CS0649 warnings telling me that there are unassigned fields when they're just assigned through the inspector. Is this ever going to be fixed?

  10. 759066ed26e69fa150636607cf2e9c32?d=mm

    reddtoric

    Jul 22, 2019 02:06

    Please reopen issue

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.