Filling list with editor scripts is empty on Play

Hi everybody.
Apologies for yet another question about Editor Scripts on this page.

I’m filling a List through an editor script, but it resets on play mode. I read about SerializeField and I guess that I missed something there.

Here are the relevant Scripts:


using UnityEngine;
using System.Collections;

public class AssetAudioPair {
	public Sprite sprite;
	public AudioClip audioFeedback;
	public string textContent;

	public AssetAudioPair(Sprite s, AudioClip a){
		this.sprite = s;
		this.audioFeedback = a;

	public AssetAudioPair(){


using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using System.Linq;

public class GameManager : MonoBehaviour
	public List<AssetAudioPair> imagePairs;
	public List<AssetAudioPair> textPairs;

// Lots of other stuff, but these are the relevant fields


using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;

public class GameManagerEditor : Editor {
	List<AudioClip> feedback;
	public override void OnInspectorGUI () {
		//Called whenever the inspector is drawn for this object.
		if (GUILayout.Button ("Fill Images")) {
			feedback = new List<AudioClip>();
			var audioPaths = from a in AssetDatabase.GetAllAssetPaths() 
						where a.Contains("/Audio/new/") 
						where a.Contains("03_WRONG") 
						select a;
			foreach(string path in audioPaths){
			var imagePaths = from s in AssetDatabase.GetAllAssetPaths ()
			            where s.Contains ("/Textures/GameUI/Images/")
			            select s;
			foreach (string path in imagePaths) {
				AssetAudioPair x = new AssetAudioPair ((AssetDatabase.LoadAssetAtPath<Sprite> (path)), null);
				if (!manager.imagePairs.Any(p => p.sprite == x.sprite)) {
					manager.imagePairs.Add (x);
			foreach(AssetAudioPair aP in manager.imagePairs){
				aP.audioFeedback = feedback[Random.Range(0,3)];
			Debug.Log (manager.imagePairs.Count);

Am I serializing the wrong fields? Am I just doing it wrong?
What am I missing?


The posted code does not show how you get the manager variable in your OnInspectorGUI.
Anyway, reason should be you didn’t mark the dirty state of your target object.
Put code below into your if(button) block,