Serialized variable can not be modified

I have an int variable set as [SerializedField]. After a while, it seems when I change the value in the Inspector, it has no affect and will not change to the new value.

I will remove the serialized line in the code completely, save the code and exit Unity. Upon loading up my project and declaring the int variable again with same variable name, it holds the old int value as if I never deleted that line of code.

I’ve had to use a different variable name so I can modify the value through the inspector. I’ve lost plenty of hours troubleshooting my code just to find out, this little quirk is the issue. It has happened several times to me over the past couple of years.

// paste example code here

How can I fix this?

It’s as simple as:

[SeralizeField] SomeType someType;

I make changes to the someType in the inspector but when I run the game, it holds the old value. This will happen to a game to where changing in the inspector is not a problem. Then at some point, I cannot longer modify. It’s odd for sure. I periodically do backups of a project. I can go to archived versions and the issue no longer exists. It’s a portion of my code that never changes. It’s in a player class that almost never gets changed and if it does, the funclionallity change does not use the variable. In this case is “startingPlayerShields”. I wanted to change it for testing and balance in the game. So during development is changed it often. After a while, it would happen to the new var field.

Thanks jwadgrl