Search Issue Tracker

Fixed in 2021.1

Fixed in 2018.4, 2019.4, 2020.1, 2020.2

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. 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 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. Response avatar

    Resolution Note (fix version 2020.2):

    Fixed in 2020.2.0b9

  3. Response avatar

    Resolution Note (fix version 2020.1):

    Fixed in 2020.1.11f1

  4. Response avatar

    Resolution Note (fix version 2019.4):

    Fixed in 2019.4.15f1

  5. Response avatar

    Resolution Note (fix version 2018.4):

    Fixed in 2018.4.29f1

Comments (82)

  1. 06d364cbcfe76a1f3362651493fafb47?d=mm

    TehMightyPotato

    Apr 08, 2020 22:41

    Yeah I imported 50+ scripts from various SDKs and now I can't see any of my actual warnings because of over 200 of those warnings...
    Can you guys please adress this?

  2. D71b64fbaf77030b93856b1a2d402f91?d=mm

    VGMFR

    Mar 05, 2020 09:44

    This issue is really terrible for warning clarity, it's a pain for all our projects. You would make a lot of developers and code cleaners very happy by prioritizing this issue!

  3. C35b9264646fd1b72f6ccfca2622c409?d=mm

    AlanMattano

    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.

  4. 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.

  5. 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.

  6. 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.

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

  8. 02f9d1cb2f157adef21c6a8148f10d82?d=mm

    Toxast

    Nov 06, 2019 08:46

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

  9. 642717413bada4a18b7cfad3a5196f49?d=mm

    mayofunk

    Oct 10, 2019 14:47

    Really??!!

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.