Why does the value of the public property of [Serializable] class persist in ScriptableObject between Editor runs ?

I have a class like this

[Serializable]
public class Team
{
	public string Name;
	public int NumberOfPlayers { get; set; }
}

and I have a ScriptableObject class like this

public class GameSettings : ScriptableObject
{
    public Team[] Teams = new Team[2];
}

when the instance of the GameSettings is selected in the Editor, in Inspector panel I can edit (as expected) only the Name field of each Team instance. Then, when the game is running, I change the values of the NumberOfPlayers properties via code, and to my surprise, these values are kept between runs of the game in the Editor.


IOW when I stop a game running in the editor and start it again, these values are not 0 (as I expect them to be since they are properties and, as I understand, shouldn’t be serialized and saved especially when the game is running).


Having a property in ScriptableObject to keep values during the game probably is not the best approach but the question is still why and where the values are kept?

I checked the GameSettings.asset and there is no such value/name serialized, neither I could find it in other files within the project folders.

Then, when the game is running, I change the values of the NumberOfPlayers properties via code, and to my surprise, these values are kept between runs of the game in the Editor.

This is one of the purpose of the Scriptable Objects.

Scriptable Objects are project assets, the same way materials, textures or prefabs are. When you change a value on those object (even at runtime), quitting play mode won’t reset the values of the assets, the same happens for ScriptableObjects.

Having a property in ScriptableObject to keep values during the game probably is not the best approach but the question is still why and where the values are kept?

I checked the GameSettings.asset and there is no such value/name serialized, neither I could find it in other files within the project folders.

The changes must be in the .asset. Make sure you have saved your project (not only the scene) : File > Save Project.

The comment below by @Bunny83 shows how to make a backing field NonSerialized. I have erased my answer here which took a different, worse, approach.