Search Issue Tracker

Fixed in 2021.1

Fix In Review for 2018.4, 2019.4

Fixed in 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

Comments (82)

  1. 8382b669e96e7229ef2670c5f253f619?d=mm

    Bip901

    Sep 23, 2020 15:37

    Solution: explicitly assign the default value to the field. E.g:

    [SerializeField] private Collider myCol;

    Becomes:

    [SerializeField] private Collider myCol = default;

  2. 7712e78c9707121675f84b312c3199b3?d=mm

    Sliem001

    Sep 09, 2020 08:03

    Unity 2020.20b1 Beta
    Problem still exists.

    Please FIX!!!

  3. B872989255a6523a27b5ac7b261af372?d=mm

    miniwolf_unity

    Sep 01, 2020 11:36

    We are investigating how to solve this. I would encourage you to add your thoughts and opinions to this thread: https://forum.unity.com/threads/suggesting-solutions-for-serializefield-warning.962112/

  4. 16a5eec5eca4550033c0e19dba3b32b8?d=mm

    darthdeus

    Aug 24, 2020 18:39

    Please fix this :( I wonder if there's some reason why this is difficult, or if Unity just prioritizes adding more features over fixing minor annoyances. I'd imagine since the compiler can see the actual attribute [SerializeField] it shouldn't be hard, but maybe I'm missing something.

  5. 825863155a210e69c430c0f85e4df049?d=mm

    Johannes_R

    Aug 10, 2020 21:18

    Unity gives me warning for not initializing my struct member variables. :(
    (Unity 2019.4)

  6. D71b64fbaf77030b93856b1a2d402f91?d=mm

    VGMFR

    Aug 07, 2020 09:00

    Each new release since a year and a half I'm checking the whole changelog praying that this issue has moved from "Known Issues" to "Release Notes". One day, maybe...

  7. 77c93f8de558bd9b1ca4442fc3db0991?d=mm

    kyuskoj

    Aug 03, 2020 03:49

    Someday ...

  8. 1ba3a9136eb7b10e279cc74ff0b9a758?d=mm

    antonsem

    Jul 29, 2020 12:59

    It is possible to suppress these warnings with csc.rsp file. But it will suppress legitimate warnings as well. I wrote about it in my blog: https://www.anton.website/suppressing-warnings-in-unity/

    I would love to see it fixed...

  9. 268e488556c0e9e604ef13d23f63ce62?d=mm

    ModLunar

    Jul 16, 2020 13:06

    I'm really glad this isn't marked "By Design". Thank you, we need this fixed.

  10. A79cda4d4ab7e50131a86c3463a8c120?d=mm

    KCAR

    Jul 10, 2020 16:18

    Unity 2020.2a Beta
    Problem still exists.

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.