🤔

CS0649#

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.

Resolution#

Either:

Assign a default value to serialized fields.

[SerializeField]
private Example _example = default;

Or

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

/nowarn:0649

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

Or

Selectively wrap serialized fields in:

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

Or

Disable it in the entire file:

// <- using statements
#pragma warning disable CS0649