- Home /
Custom Inspector List Resetting after Play
So, I am making a custom inspector and I have a list that I want to display whenever an element is added. This works fine until I enter play mode or close unity. I have a feeling this has something to do with all the lists that exist here, so I'm leaving all the simple code out. Here are my scripts.
Mission Step:
[System.Serializable]
public class MissionStep : ScriptableObject {
// Other Code...
public List<Item> itemsToBeFetched;
public List<NPC> npcsToBeTalked;
}
Mission Script:
[System.Serializable]
public class Mission : ScriptableObject {
// Other Code...
[HideInInspector]
public List<MissionStep> missionStepsList;
}
Custom Editor:
public class MissionEditor : Editor {
Mission mission;
MissionStep missionStep;
// Other Code...
public override void OnInspectorGUI()
{
base.OnInspectorGUI ();
GUILayout.Space (5);
// Create "Mission Steps" label
GUILayout.Label ("Mission Steps", EditorStyles.boldLabel);
MissionStepButtons ();
MissionStepHandler ();
if(GUI.changed)
{
EditorUtility.SetDirty (mission);
}
}
// Other Code....
private void MissionStepHandler()
{
for(int i = 0; i < mission.missionStepsList.Count; i++)
{
missionStep = mission.missionStepsList [i];
// Other code...
}
}
I know the list doesn't reset because if I do Debug.Log(list.Count) it shows that it has elements. But whenever I try to access missionStep after I click play or re-open unity, I get an error saying that it is not referenced. Through debugging, I found out that I can't access the elements that I created in the list BEFORE I clicked play/exit, but once I create new elements, it accesses them just fine.
Anyone got any idea what is happening? Thank you