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

5

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 (59)

  1. Abcf103768e747515c8a3a2733b4ccf1?d=mm

    TextusGames

    Nov 24, 2019 21:51

    Ok. Now we will wait for new Roslyn in unity.
    There is a good chance error will be fixed sometime after that.

  2. 609235fd5506ccec488822f0f2574a23?d=mm

    unity-marcus

    Nov 15, 2019 08:02

    This is a really annoying Unity bug still present in 2019.3.0b10. The suggested workarounds are not feasible because I do not want to add pragmas to my entire code base. Using a csc.rsp would suppress all CS0649 warnings including valid ones for non-SerializeField occurrences and is not a valid solution either. Please fix this.

  3. 17e9298cf354205067c6cae76802bb47?d=mm

    nomadic

    Nov 12, 2019 22:28

    This seems to contradict the best Unity design patterns and even the official example projects. Really hope this is revisited.

    Also the csc.rsp file should contain "-nowarn:0649" not "/nowarn:0649" -- or at least that is what is working for my environment.

  4. D44d589267c96109167726ab55df4349?d=mm

    Lorash

    Nov 11, 2019 21:14

    Microsoft has added the required "magic" to Roslyn so this can be fixed: https://github.com/dotnet/roslyn/pull/36067

  5. 02f9d1cb2f157adef21c6a8148f10d82?d=mm

    Toxast

    Nov 06, 2019 08:46

    Before this "design" I was able to see real issues in the console.

  6. 642717413bada4a18b7cfad3a5196f49?d=mm

    mayofunk

    Oct 10, 2019 14:47

    Really??!!

  7. 947c8309c6e842a5b86c63a297b933cd?d=mm

    LeFlown

    Oct 10, 2019 14:44

    I agree with everyone here. This needs to be adressed, please.

  8. 7d7224d5ef39fd679f9efed50c5912de?d=mm

    michaelday008

    Oct 09, 2019 07:43

    You guys only have 100 warnings? I have about 340 of these because I use a lot of serialized attributes over about 200 .cs files. I'm not going to go through 200 scripts and add pragmas to them...

    Setting default Values is NOT a solution because I have had multiple instances where somehow a default value overrode the value I set in the inspector, and I had to go remove the default values from 100 objects to prevent values I specifically set from disappearing!!!

    I'm not sure when it happens (maybe I clicked revert accidentally or something), but whatever the case it causes hours of headaches when it does occur and there is literally NO warning telling you that a bunch of serialized attributes you set on a hundred objects are about to be reset to defaults and override your values.

  9. D376d891ab442d46b58f26d407ccd162?d=mm

    karolwieczorek9

    Oct 08, 2019 13:44

    Is there any chance to reopen this? really annoying bug

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.