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
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
-
Lyje
Feb 09, 2019 13:51
Labelling this as "by design" is, frankly, absurd. It actively opposes the purpose of warnings. In this case a warning is issued when the programmer uses good practice, thus discouraging it. Warnings are designed specifically to discourage bad practices.
-
SpencerMowrey
Feb 01, 2019 06:40
Boo bad design. Not sure why this could slip through. I guess we want newer Roslyn and this is what we get. Honestly this is a long standing issue that Unity should address in an alternative way. On compile complete if warning cs0649 is field SerializedField... yes? Don't show the stinking warning! Why rely and wait on Roslyn to get fixed? You have control over what is displayed in the console.
-
potato_based_username
Jan 25, 2019 23:30
If this is by design, then your design is terrible and you should be ashamed of it.
-
AlanMattano
Jan 24, 2019 17:01
I wish to vote for this issue or at least a C# video tutorial in the learning section explaining how to declare my variables now!
-
Node
Jan 19, 2019 11:00
i agree. if this is by design, then the design should be fixed. because the current design either forces you to make everything public which violates the most basic OOP principles, or just live with warnings and hope that you don't miss any actual useful warning within the spam of useless ones. disabling them in every file that has serialized fields is ridiculous.
this is definitely a design flaw and should be fixed. i just hope someone notices this within a resolved issue...
-
mikedg1
Jan 01, 2019 12:42
If this is by design, then the design has a bug, where do we submit reports for that?
-
MechEthan
Dec 19, 2018 17:41
Update: after further research, it looks like a fix is in the works: https://forum.unity.com/threads/warning-cs0649-not-suppressed-properly-when-field-is-marked-as-serializefield.556009/#post-3954073
https://github.com/dotnet/roslyn/issues/30172
It'll just take time.
-
MechEthan
Dec 19, 2018 17:19
I wonder if fixing this would require a modification to the Rosyln compiler to allow Attributes to flag a field as used? This IS actually possible because Rosyln is open source, and Unity has a seat at the .NET Foundation table.
Alternately, they could inject the pragma statements at build time for all [SerializeField] entries.
Regardless, "By Design" is kind of a lie. More like "ignoring this regression because fixing it is hard."
-
OndraPaska
Dec 17, 2018 21:51
This should be fixed, using [SerializeField] is the preferred method so it should be made easy, having everything public is bad practice.
-
ModLunar
Dec 15, 2018 16:31
Ahh no! I didn't read that someone already said what I said with the #pragma warning disable option.. sorry in advance! Lol :(
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [2020.3] Play Mode has visual artifacts when Graphics API is set to DirectX12 with Dynamic Resolution enabled
- White texture appears when setting “RenderTextureFormat.Depth” to “RenderTexture” on the Camera
- Cursor is visible when using “Cursor.lockState = CursorLockMode.Locked” and “Cursor.visible = false”
- Material.SetOverrideTag setting LightMode tag has no effect
- Decal is not rendered when in Camera component Culling Mask dropdown field Default is unselected
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.