- Home /
Custom Editor: Weird reset when clicking Play
I'm creating a custom editor and I'm having a weird issue.
When I change the values in the custom editor and click Play, the values get reset to their previous values... But... If I make a change in the custom inspector Script (any change, like deleting a character, then adding it again), then re-save, and then change the values in the inspector, then these values act as expected and don't get reset when I then click Play.
I'm using Unity 4.1.5f1 on a OSX 10.8.4.
Here is a simplified version of the custom inspector (I'm also using Lists of a wrapper class containing a basic int[] arrays), but the reset occurs also with these basic IntFields:
// MachineConfig.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class MachineConfig : MonoBehaviour {
public int symbolHeight;
public int symbolWidth;
}
// MachineConfigInspector.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor( typeof(MachineConfig) )]
public class MachineConfigInspector : Editor {
public override void OnInspectorGUI () {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Symbol Width:", GUILayout.Width(80));
machineConf.symbolWidth = EditorGUILayout.IntField(machineConf.symbolWidth, GUILayout.Width(40));
machineConf.symbolHeight = EditorGUILayout.IntField(machineConf.symbolHeight, GUILayout.Width(40));
EditorGUILayout.EndHorizontal();
}
}
...I also tried adding:
if (GUI.changed) {
EditorUtility.SetDirty(machineConf);
}
But it doesn't seem to help...
Any help about why this is happening will be much appreciated :)
Thanks!
Answer by soundwav_ · Aug 11, 2013 at 04:18 AM
It seems like the issue was because I was marking a MonoBehaviour as Serializable.
When I removed the [System.Serializable]
from above the class declaration (`public class MachineConfig : MonoBehaviour`), all the data seems to be saved properly.