Search Issue Tracker
Fixed in 2021.1.X
Fixed in 2018.4.X, 2019.4.X, 2020.1.X, 2020.2.X
[SerializedField] fields produce "Field is never assigned to..." warning
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 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
Resolution Note (fix version 2020.2):
Fixed in 2020.2.0b9
Resolution Note (fix version 2020.1):
Fixed in 2020.1.11f1
Resolution Note (fix version 2019.4):
Fixed in 2019.4.15f1
Resolution Note (fix version 2018.4):
Fixed in 2018.4.29f1
Sep 23, 2020 15:37
Solution: explicitly assign the default value to the field. E.g:
[SerializeField] private Collider myCol;
[SerializeField] private Collider myCol = default;
Sep 09, 2020 08:03
Unity 2020.20b1 Beta
Problem still exists.
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/
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.
Aug 10, 2020 21:18
Unity gives me warning for not initializing my struct member variables. :(
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...
Aug 03, 2020 03:49
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...
Jul 16, 2020 13:06
I'm really glad this isn't marked "By Design". Thank you, we need this fixed.
Jul 10, 2020 16:18
Unity 2020.2a Beta
Problem still exists.
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- NullReferenceException error thrown when changing Scenes in Play Mode
- Crash on "'anonymous namespace'::ConvertFBXShapes" when importing an FBX file
- Crash on Transform::RemoveFromParent when Object.DestroyImmediate() is called on Transform
- [Linux] Player consumes more CPU resources when it is running in the background
- Save process is triggered every time when prefab property values are changed by dragging
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.
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.