Keep List data between 'play' tests

Hi,
I have a ‘manager’ script on a gameObject that creates a List, ‘itemList’ of a custom class, ‘item’. I also have a custom editor window that accesses the itemList on that gameObject and allows dynamic adding/removing/editing of the List items. The problem is that when play is pressed, the List is reset and all the items are lost.

I’m guessing the reason is to do with instancing, as the code to create the list (in the ‘manager’ script):

Public List<item> itemList = new List<item>();

is creating a new instance every time play is pressed.

My question is how can I make the List ‘itemList’ persistent between the editor and the game in play mode so that it is not reset? I’m fairly inexperienced in coding- just learning as I go along, so any help appreciated. I also am only familiar with C# at this point.

Thanks.

Sounds like you want to make your object serializable, you can do it by labeling the class and any private properties in it that you want to be persistent like this:

[System.Serializable]
public class PersistentClass

[SerializeField]
private int myVar = 0;

More info on it here.