Values get lost after starting the game in editor

After setting some values per Unity Editor-Script and start the game in editor, those values get lost. Example:

// Store values in a Unity3D GameObject
public class RuntimeClass : MonoBehaviour {
    public List<string> values;
}

// Set values in editor function
public class EditorClass{
    public void setValues(){
        values.Add("Foo");
        values.Add("Bar");
    }
}

During Edit-Time in the Unity-Editor all values are shown correct in the Inspector-Panel. After starting the game in editor those values get lost. I think the problem is that the values are overriden by the internal Unity3D Serialisation-System. So is there a way to force serialisation after seting some values?

Thanks in advanced,
Christian

Whenever you make changes to a script through a custom editor/inspector, you need to flag it so that Unity knows what changes you want to keep. You do this through the SetDirty() function.

read Shawn’s answer

I remember hitting a similar issue a while ago, its one of the few questions I ever ask on here, I came to the conclusion that only arrays and primitive types would serialize correctly.

Alternatively, I learned that class deriving from ScriptableObject does serialize the way you expect them.

If I’m correct, the easiest way is probably to use an array instead of a list. You could implement extension methods to give arrays the .Add() functionality since you don’t care for the editor’s performance.