CS0649 on multi-variable declaration
I am getting the following warning, and would like to understand why Unity doesn't like it.
Assets/Scripts/UIController.cs(9,20): warning CS0649:
Field `UIController.dayText' is never assigned to, and will always have its default value `null'
This message is driven by the following declaration:
[SerializeField]
Text cityText, dayText;
Whilst the declaration works as expected, I get that warning. I can get rid of the warning if I put each on its own line, thus:
[SerializeField]
Text cityText;
[SerializeField]
Text dayText;
Why doesn't Unity like the first version, is there some kind of standard that says I should put each on its own line with its own [SerializeField]?
Good day.
As it says, the variable dayText is null and you never assign something to it.
As it has [SerializeField], both cityText and dayText show in the inspector and both are assigned values in the inspector based upon dragging the relevant Text field into the corresponding value in the inspector
Both cityText and dayText used in the code later correctly update the text field as expected
dayText.text = string.Format("Day: {0}", city.Day.ToString());
For some reason they are beeing unassigned, or are different variables, from different instances.