Unity Console warning CS0649 "Field is never assigned" and [SerializeField]

Completed

In Rider there is no warnings and along with [SerializeField] properties I see "Set by unity" tooltip, but in Unity console I got a bunch of warnings.

Well... about 80 warnings for now

0
4 comments
Avatar
Permanently deleted user

This is a Unity bug AFAIK. I've solved it this way:

Create file named:

csc.rsp

Put inside the file this content:

-nowarn:0649

Then put this file into your Assets folder.

No more 0649 warnings in the editor =)

0

Do you know maybe do they have plans to fix this? I don't think I encountered this issue before, this might be introduced in Unity 2018 lifecycle. 

Thanks for your solution! I'll use it for now with hope to get a fix from unity team :)

0

@Andrew 

this is not a Unity bug (unfortunately). It is a "side effect" of Unity switching over to Roslyn.

Mono (the old c# compiler) never emitted those warnings before because it had a bug which we benefited from. The good news is the Roslyn devs are aware of this issue and are working on a fix for us.

The issue with the csc.rsp file is that it will suppress all 649 warnings globally. For now I solve it by enclosing all my [serializedField] in

#pragma warning disable 649
#pragma warning restore 649
0

My solution is to simply initialize the value and then get resharper to ignore the setting of the value like so:

[SerializeField]
// ReSharper disable once RedundantDefaultMemberInitializer - done to avoid editor warning
private LiveRawSensorData liveRawSensorData = null;
0

Please sign in to leave a comment.