"Make field readonly" error. Private variables have to be readonly now?

Every time I make a private variable visual studio gives me an error saying “Make field readonly.” I have never had this issue before. Is this new with Unity 2019? Or is it on visual studio’s end? Does making a variable readonly affect anything?

I’m pretty sure you don’t get an error but most likely a warning / suggestion. I’m pretty sure it’s “IDE0044” which is triggered by the visual studio code analyzer when it detects a private variable that is either uninitialized or is only assigned either by a field initializer or inside the constructor of the class. Since no body else (usually) can assign a value to that field the cody analyzer suggest that you make the field read only.

Making a field read only will prevent that you can assign any new value to that field. You barely need readonly fields unless they are actual constants.

Without more context we can’t suggest any actions you should / might take. Since it’s just a warning / notice you can simply ignore it.

Do you use (change the value) of that private variable in the code, or is it just one value that stays the same through the code?

Making a variable readonly does what you would expect : it only allows you to read its value. So if you want to change it within the code, it’s better to not set it to readonly.

Also, what are your Visual Studio and Unity versions?