Field 'foo' is never assigned to, and will always have its default value 'null'

It is extremely common to see this warning in Unity because of an unassigned serialized variable. Unity's serializer populates serialized values completely unseen by the compiler, so it does not understand that the value is assigned at runtime.



Assign a default value to serialized fields.

private Example _example = default;


Create a file named csc.rsp in Assets that contains:


This will silence the warning across the project, even when valid, but a functioning IDE should still indicate when a variable is unused.


Selectively wrap serialized fields in:

#pragma warning disable CS0649
// <- Serialized fields
#pragma warning restore CS0649


Disable it in the entire file:

// <- using statements
#pragma warning disable CS0649