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.




Found in



Issue ID




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



1. Open the attached project (
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


    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.


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

  1. C35b9264646fd1b72f6ccfca2622c409?d=mm


    Feb 22, 2020 03:39

    I forget and now I return back and look for the solution. takes me 1h. And I'm afraid of giving value = 0 to my 200 variables: I do not know if override the inspector ones. Variables are from imported assets from the asset store.

  2. Abcf103768e747515c8a3a2733b4ccf1?d=mm


    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.

  3. 609235fd5506ccec488822f0f2574a23?d=mm


    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.

  4. 17e9298cf354205067c6cae76802bb47?d=mm


    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.

  5. D44d589267c96109167726ab55df4349?d=mm


    Nov 11, 2019 21:14

    Microsoft has added the required "magic" to Roslyn so this can be fixed:

  6. 02f9d1cb2f157adef21c6a8148f10d82?d=mm


    Nov 06, 2019 08:46

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

  7. 642717413bada4a18b7cfad3a5196f49?d=mm


    Oct 10, 2019 14:47


  8. 947c8309c6e842a5b86c63a297b933cd?d=mm


    Oct 10, 2019 14:44

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

  9. 7d7224d5ef39fd679f9efed50c5912de?d=mm


    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.

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.