I have a script like this:
public class A: MonoBehaviour {
public bool x = false;
}
... and a Custom Editor like this:
[CustomEditor(typeof(A))]
public class A_E: Editor
{
public override void OnInspectorGUI()
{
A a= target as A;
if (a== null || a.gameObject == null) return;
a.x = !EditorGUILayout.Toggle("x", !a.x);
}
}
When I enter play mode, the property resets.
I tried fixing it by adding:
if(GUI.changed) EditorUtility.SetDirty(a);
However this only fixed it for play mode.
If I save and close the scene, it resets to the default.
Also, the scene is not set to dirty, if I make changes to the component through the custom editor.