Variable values not updating when script edited

I have several public static variables in a C# script, which aren’t listed in the inspector. When I edit the script in MonoDevelop to change the values of those variables, the new values aren’t being reflected when I run the game in the editor, although any other changes I make to the script at the same time work as expected.

Apparently the values of public variables are cached by the Unity editor when it loads the scene, overriding whatever changes I make to them in the script from that point on, until I shut down the editor and restart it.

I removed the [System.Serializable] from above the class definition and tried using [System.NonSerialized] on the variables within it, but that didn’t make any difference. As noted above, none of these values are listed in the inspector anyway, so I don’t understand why they don’t just always reflect what’s in the script, as you’d expect them to.

Is there any way to stop Unity overriding variable values like this, or to force it to flush whatever hidden cache it’s pulling them from without having to restart the editor or reload the project every time I make a change?

NOTE: I can’t really change the variables to private or non-static, or set their values in the Start script instead of where I declare them, as I’ve seen suggested in previous threads, as they’re being used to initialise variables in other scripts for export to an external file.

Any help would be much appreciated.

I know this is like a year later, but you can set the variable in question to be private, save your script, then change the variable back to public and save it again. It worked for me.

So,

public float myNum = 10;

to

private float myNum = 10;

and back to public after you save it.