Search Issue Tracker

Fixed in 2021.1.X

Fixed in 2018.4.X, 2019.4.X, 2020.1.X, 2020.2.X

Votes

216

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. 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. Resolution Note (fix version 2021.1):

    A list where you can pass additional compiler arguments as well as a toggle to suppress common warnings is added in the Player Settings
    Fixed in 2021.1.0a2

  2. Resolution Note (fix version 2020.2):

    Fixed in 2020.2.0b9

  3. Resolution Note (fix version 2020.1):

    Fixed in 2020.1.11f1

  4. Resolution Note (fix version 2019.4):

    Fixed in 2019.4.15f1

  5. Resolution Note (fix version 2018.4):

    Fixed in 2018.4.29f1

Comments (84)

  1. 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!

  2. 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?

  3. reddtoric

    Jul 22, 2019 02:06

    Please reopen issue

  4. JJChai

    Jul 11, 2019 13:22

    This is still happening in my project (version 2019.3.0a7).

  5. Kamyker

    Jun 30, 2019 17:24

    It got resolved from Rosalyn side 2 weeks ago, now it's time for Unity to implement it. https://forum.unity.com/threads/feature-request-use-new-diagnosticsuppressor-api-to-suppress-cs0649-on-serializefield.697514/

  6. Manoadamro

    Jun 28, 2019 15:36

    Still a problem in latest version (2019.3.0a4)

    [SerializeField] private bool _debug;

    "warning CS0649: Field 'SelectTool._debug' is never assigned to, and will always have its default value false"

    Please don't say this is by design, a warning should warn the user that they have done something wrong, not that they have done something completely valid but the engine can't handle it...

    and if it is by design and everything has to be public, why do we even have the [SerialiseField] attribute?

    this feels unfinished to me

  7. Zullar

    Jun 18, 2019 03:30

    This is frustrating. I just upgraded and now I'm getting warnings all over. I want my fields private to encapsulate, and I want them serialized to expose them in the inspector. This shouldn't generate a warning.

  8. guneyozsan

    May 30, 2019 12:31

    The most non-sense "By Design" tag I've ever seen.
    This completely makes unable to make use of CS0649 warning, and, it spams the console with hundreds of lines of warnings.

    Either disable it or fix it. A missing feature is better than a non-working and spamming one!

  9. Artifact-Jesse

    May 25, 2019 05:41

    There is no way this is By Design... Please reopen this issue. It's driving me nuts.

  10. AlanMattano

    May 08, 2019 15:27

    Can Unity make a video about this .Net 4.X problem?

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.