Search Issue Tracker

By Design

Votes

1

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

Resolution:

The new C# compiler is correct in reporting the additional warnings. Unfortunately, there is no magic to fix this.

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

  1. F6bb6aa141dea8490a3a709c3e223adc?d=mm

    JJChai

    Jul 11, 2019 13:22

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

  2. 9c2381ec5cbfa0cb0c262e8a4ad4441b?d=mm

    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/

  3. 1970c0eb792cd0a79747410df4cb699e?d=mm

    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

  4. 783d50c318ea066fe50bde531bf259b3?d=mm

    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.

  5. 19bcab4c25eb264b21619cd7a8a15481?d=mm

    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!

  6. 41b02dbd30f08d896b361aabf9fa7032?d=mm

    Artifact-Jesse

    May 25, 2019 05:41

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

  7. C35b9264646fd1b72f6ccfca2622c409?d=mm

    AlanMattano

    May 08, 2019 15:27

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

  8. Dd8da009afba747778db5dcb5866de9e?d=mm

    Alexees

    Apr 26, 2019 12:49

    What makes this unnecessarily tedious is the fact that you can use "= default" for every field.

  9. 3e2ae4101faf1b19afa71b4540d5dac6?d=mm

    MrDude

    Apr 21, 2019 06:10

    By design, declare your private fields public.
    That makes total sense. why is anyone complaining about this?

  10. Cb0088335925614ac61657710cac4207?d=mm

    Gillissie

    Apr 16, 2019 18:00

    While it's true that it's bad design for these warnings to show up, it's also bad practice to declare inspector properties without initializing them with default values. Initialize your inspector property variables with default values to eliminate the warnings.

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.