Private variable losing its value on editor script

I’m building a set of editor scripts to help on the level design of a game.

All the public variables I created keep their values and work perfectly, but as soon as I run the game, all the private variables on those editor scripts lose their values and get set to null. If I literally just make the variable public that behavior doesn’t happen.

I’m thinking that since the variable is only used in the editor, it gets optimized out once you run the game, and when it comes back to the editor it’s reinitialized or something.
Do you guys know what can cause this sort of behavior and if there is a solution, other than just making the stuff public?

You need to [SerializeField] or @SerializeField the private variables to keep them the same between edit and play mode.

@SerializeField private var edOpen;

[SerializeField] private bool edOpen = false;