Problem keeping List variables saved when triggering play button

I have made an Editor script (inspector) to a target script called BossScript. the BossScript have 2 vairables of type List< Obsticles>, and List< bool>. Im modifying these variables from the editor script. it all works fine till i trigger the play button and then the variables reset… (like if i had 5 objects on the list, it gets to 0). It worked fine before the last update tho, i used to do it all the time. i tried something with the Serialization but it didn’t work either…

Editor script:

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

[CustomEditor(typeof(BossScript))] 

public class BossScript_Editor : Editor 
{ 
    public override void OnInspectorGUI() 
    { 
        BossScript t = target as BossScript; 

        GUI.color = Color.green; 
        if (GUILayout.Button("Add new obsticle")) 
        { 
            t.obsticles.Add(new Obsticle()); 
            t.showObsticles.Add(false); 
        } 

        EditorGUILayout.Space(); 
        EditorGUILayout.Space(); 

        GUI.color = Color.white; 
        for (int i = 0; i < t.obsticles.Count; i++) 
        { 
            t.showObsticles _= EditorGUILayout.Foldout(t.showObsticles*, ("Obsticle " + i.ToString()));*_

if(t.showObsticles*)*
{
EditorGUILayout.LabelField(“Properties:”);

t.obsticles_.time = EditorGUILayout.FloatField(“Time:”, t.obsticles*.time);*_

t.obsticles_.isCurrentObjectPosition = EditorGUILayout.Toggle(“Current position?”, t.obsticles*.isCurrentObjectPosition);_
_if (t.obsticles.isCurrentObjectPosition)
{
t.obsticles.pos = EditorGUILayout.Vector3Field(“Offset:”, t.obsticles.pos);
}
else
{
t.obsticles.pos = EditorGUILayout.Vector3Field(“Position:”, t.obsticles.pos);
}*_

t.obsticles_.obj = (GameObject)EditorGUILayout.ObjectField(t.obsticles*.obj, typeof(GameObject));*_

GUI.color = Color.red;
if(GUILayout.Button(“Delete Obsticle”))
{
t.obsticles.RemoveAt(i);
t.showObsticles.RemoveAt(i);
}
GUI.color = Color.white;

EditorGUILayout.Space();

EditorGUILayout.LabelField(“Effects”);

EditorGUILayout.Space();
}
}

if (GUI.changed)
{
EditorUtility.SetDirty(target);
}
}
}
BossScript.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class BossScript : MonoBehaviour
{
public List obsticles = new List();
public List showObsticles = new List();

void Awake()
{
StartCoroutine(SpawnObsticles());
}

private IEnumerator SpawnObsticles()
{
float startTime = Time.time;
float lastInstantiationTime;

yield return new WaitForSeconds(obsticles[0].time + startTime);

lastInstantiationTime = Time.time;

for (int i = 0; i < obsticles.Count - 1; i++)
{
print(i + " TIME: " + Time.time);
yield return new WaitForSeconds(obsticles[i + 1].time - lastInstantiationTime + startTime);

lastInstantiationTime = Time.time;
}
}
}

public class Obsticle
{
public float time;
public bool isCurrentObjectPosition;
public Vector3 pos;
public GameObject obj;
}

You cannot save values that are not serializable. Try with this:

[System.Serializable]
public class Obstacle 
{ 
    public float time; 
    public bool isCurrentObjectPosition; 
    public Vector3 pos; 
    public GameObject obj; 
}

And by the way, the correct spelling is Obstacle. Because obsticle means the female testicle and I don’t think it is what you mean here.

Try commenting out the two new’s in BossScript.

In my limited EditorScript experience, not in 3.5, I believe my lists were always zeroed out on running until I made code look like the standard Inspector: have BossScript only declare List<Obsticle> obsticles; and move the “new” to the Editor script: if(t.obsticles==null) new it. In your case, you wouldn’t need that second part until you started on a fresh BossScript.

Plus, this is a good chance to practice Search and Replace (^H obsticle obstacle)