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

    Apr 22, 2020 02:24

    oops! wrong ticket

  2. Inboxninja

    Apr 22, 2020 02:20

    this has been "postponed" for 6 years. Can we get a fix please?

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

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

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

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

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

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

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

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.