Editor Scripts: Variables Disappear After Pressing Play

Hi,

I am using an editor script to call some inititialisation dunctions which set various fields, but some of these fields dissappear after pressing the play button. Why is this? I am absolutely certain that these variables are not being removed by my own code, as when I manually set these variables they are not deleted when play mode is activated. It must be something to do with how Unity deals with manual initiation vs initiating variables in editor scripts. All the fields that are initialised have the [SerializeField] tag. My code is as follows:

Editor Script initialisation

        if (GUILayout.Button("Initialise Map"))
        {
            map.initialiseAllComponents();
        }
public void initialiseAllComponents()
    {
        foreach (MapSection s in map) {
            s.initialise();
        }
        if (playerRacer != null) {
            playerRacer.playerRacerStart();
        }
    }

This then iterates through all the objects I need to be initialised for the scene. There are a lot of things initialised here, so I will not go through them all. Suffice to say most of them are simple variable assignments that provably work in the scene, and then dissappear when the play button is pressed. For some reason some of these variables persist, whilst others do not. There is one case where an object of the same type remains instatiated for one object, but not another. I have read that this may be something to do with fields being serialized, and a solution may be to make a scene dirty? Though I am not sure whether this is the best solution, and I cannot explain why some stay initialised and others do not. Can anyone advise how I can keep these initialisations from being deleted once play is pressed? If anything is unclear or you feel that you need any more information, feel free to ask.

Thanks in advance

Bump

Can anybody help with this? Is this thread not relevant to these forums? If it isnt I am happy to move it to another forum. If not am I being clear enough with what the issue is? I am happy to clarify if that is the case.

Late to the party, but here is the solution that worked for me:
EditorUtility.SetDirty(myComponentThatWantsSaving)
source: editor script resetting variables when play mode is triggered - Questions & Answers - Unity Discussions