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. 51fe144949b3926795b04c14e7466e3c?d=mm

    Marakino

    Dec 01, 2018 23:33

    I agree with Flavelius.

    Using the [SerializeField] attribute should prevent the all these warnings, otherwise, it makes no sense to use the attribute at all.

    I thought the whole point of [SerializeField] was so that we could have fields visible in the inspector while keeping them private.

    Is this truly considered "by design"?

  2. B797449429747ef4341b4939a00b2ce8?d=mm

    Flavelius

    Nov 21, 2018 06:41

    The compiler is wrong in reporting the additional warnings. [SerializeField] is most prominently used exactly to assign values in the inspector. Unity also is all about magic functions and magic switches, so this should and can most likely be adjusted (the previous compiler had this magic adjustment, showing that it must be possible).

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.