- Home /
Custom Editor Fields Being Reset After Entering Play Mode
I just started experimenting with the Unity Editor and I have a problem. When I hit play, the variables reset. I am using a scriptable object script, to which I have made an editor script. I tried using EditorUtility.SetDirty(target) and PrefabUtility.RecordPrefabInstancePropertyModifications(target), but none worked for me.
using UnityEditor; using UnityEngine;
[CustomEditor(typeof(Item_Scriptable_Object))] public class Item_Scriptable_Object_Editor : Editor {
bool isKey; KeyColor keycolor;
new string name;
Sprite sprite;
Mesh mesh;
Material material;
bool infiniteUses;
int uses;
public override void OnInspectorGUI()
{
Item_Scriptable_Object item = (Item_Scriptable_Object)target;
item.isKey = GUILayout.Toggle(isKey, "Is Key");
isKey = item.isKey;
if(isKey)
{
item.keycolor = (KeyColor)EditorGUILayout.EnumPopup("Key Color: ", keycolor);
keycolor = item.keycolor;
item.uses = 1;
}
else
{
}
}
}
This is my editor code. Thanks.
Your answer
Follow this Question
Related Questions
EditorGUI add SortingLayer-like list to custom Editor 1 Answer
Unity Editor script in DLL 1 Answer
Event for loading component in the editor 2 Answers
Get the highlighted variable in the inspector 0 Answers
Perform action before script compilation 0 Answers