List is being cleared when entering Play Mode

Hi, Having some trouble with a List I’m creating in Edit mode being cleared somehow when I enter play mode.

here’s a simple setup:

public class Test : MonoBehaviour {

	public readonly List<int> testList = new List<int>();
	
	void Start() {		
		Debug.Log(testList.Count) // always returns 0
	}
}

[CustomEditor(typeof(Test))]
public class TestEditor : Editor {
	
	public override void OnInspectorGUI() {	
		Test test = (Test)target;	
		EditorGUILayout.LabelField("Ints ", test.testList.Count.ToString()); //return correct number in inspector
		
		if (GUILayout.Button("Add Int")) {
			test.testList.Add(1); //adds the value 1 to the testList
		}
	}
}

All this does it make a list of ints which a custom inspector can increase the amount of. For some reason this list data is lost when I hit play. I really really really really really really really really would like that data to remain. Really.

If this isn’t possible, how can you create data for an object during edit mode and have it carry across to play mode?

Thanks.

Take the “readonly” out.

–Eric

Thanksyou