[Editor Extensions] Editing Lists and Saving the Data

Hi all,

I’ve been developing an Editor Extension to edit the contents of a list, in my case I’m aiming to have it so designers can easily create trophies for the game.

here is my code for the window, for some reason the data comes up as null. Can someone people explain to me how to achieve this? Think I’m just having a break freeze.


Okay I’m getting somewhere, so far I’ve produced a text box and assigned a value. However it’s data isn’t currently being saved when you close the window and re-open, but rather it becomes something else.

My current code is as follows.


using UnityEngine;
using System.Collections;

public class Trophy {

    public int id = 0;
    public string name = "";
    public string description = "";
    public TrophyType type = TrophyType.Bronze;

    public Trophy(int _id, string _name, string _description, TrophyType _type) {
        id = _id;
        name = _name;
        description = _description;
        type = _type;

public enum TrophyType {


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

public class TrophyEditor : EditorWindow {

    public List<Trophy> trophies = new List<Trophy>();
    int index = 1;

    [MenuItem("Tools/Trophy Editor")]
    static void ShowWindow() {

    void Awake() {
        trophies.Add(new Trophy(0, "Test", "Description", TrophyType.Bronze));

    void OnGUI() {
        EditorGUILayout.HelpBox("Simple dynamic trophy editor.", MessageType.Info);

        foreach (Trophy t in trophies) {
            t.id = EditorGUILayout.IntField(t.id);
            t.name = EditorGUILayout.TextField(t.name);
            t.description = EditorGUILayout.TextField(t.description);
            t.type = (TrophyType)EditorGUILayout.EnumPopup(t.type);

        if (GUILayout.Button("Add")) {
        Debug.Log(trophies[index - 1].name);

You should create a ScriptableObject subclass that contains your list of Trophies and then create an instance of that asset. Then make a custom inspector for that class type. It’ll work very similarly to your existing code, but the ScriptableObject is something that Unity knows how to save. You’ll just want to either use EditorGUI.PropertyField along with SerializedObject’s updateProperties calls or use EditorUtility.SetDirty() if you modify the SerializedObject directly so that Unity knows it’s changed and needs saving.