Prevent Prefab variables from being saved?

If I were to say something like this at runtime:

void Start (){
     Resources.Load("myPrefab").GetComponent<MyComponent>().myPublicVariable = 17;

And then I exit runtime, the variable will still be saved as 17 in Editor and will continue to be when I reload the game. But if I close and reopen Unity, myPublicVariable will be reverted back to its original value, like 0 or something.

BUT, I tested that if I modify one of myPrefab’s values in Editor, it will also keep myPublicVariable as 17, even if I exit Unity.

My question is: how can I prevent Unity from saving modified prefab values in Editor in the first place?

For future reference, since this is a high google hit:

[System.NonSerialized] int myThing;

If you change the prefab, then this should affect the prefab. I’m actually surprised that when you save the project it doesn’t update the prefab for good.

Reading between the lines, I THINK what you are trying to do is have myPublicVariable a global thing that can be updated in the game play later (some kind of strength attribute).

So here is another way to do it:

class MyComponent: MonoBehaviour
  public static int sharedVariable=0;
  public int myPublicVariable;

  void Awake()

You can then replace the update variable with: MyComponent.sharedVariable=17

Every time a prefab is instantiated, it will read the shared variable. But when the game ends, the static variable will be reset (which is what you needed).