- Home /
Values in editor script resetting
In my editor script, values get reset to default when entering play mode or deselecting the object. I've seen this question many times, but none of the answers given seem to work for me. [SerializeField] doesn't seem to work, and it doesn't make a difference if its public or private. This is the part of my code that does all the value setting:
[CustomEditor(typeof(BezierPath))]
public class BezierPathEditor : Editor {
[SerializeField] private Color lineColorStart = Color.red;
[SerializeField] private Color lineColorEnd = Color.blue;
[SerializeField] private bool drawNodeHandles = true;
[SerializeField] private bool disjoint = false;
[SerializeField] private float lineResolution = 0.1f;
...
public override void OnInspectorGUI()
{
DrawDefaultInspector();
EditorGUIUtility.LookLikeControls();
EditorGUILayout.Separator();
//Draw transform handles option
drawNodeHandles = EditorGUILayout.Toggle("Show Handles:", drawNodeHandles);
//Disjoint Handles option
disjoint = EditorGUILayout.Toggle("Disjoint Handles:", disjoint);
EditorGUILayout.Separator();
//Line resolution
lineResolution = EditorGUILayout.Slider("Curve Preview Resolution:", lineResolution, 0.01f, 1);
EditorGUILayout.Separator();
//Line Color Picker
Rect colorRectStart = EditorGUILayout.BeginHorizontal();
colorRectStart.x = 115;
colorRectStart.width = 125;
colorRectStart.height = 15;
GUILayout.Label("Start Line Color:", "BoldLabel");
lineColorStart = EditorGUI.ColorField(colorRectStart, lineColorStart);
EditorGUILayout.EndHorizontal();
Rect colorRectEnd = EditorGUILayout.BeginHorizontal();
colorRectEnd.x = 115;
colorRectEnd.width = 125;
colorRectEnd.height = 15;
GUILayout.Label("End Line Color:", "BoldLabel");
lineColorEnd = EditorGUI.ColorField(colorRectEnd, lineColorEnd);
EditorGUILayout.EndHorizontal();
You'll notice that i use DrawDefaultInspector() to show a few variables from the regular script this editor is used for, but those values are NOT reset. Just to make sure its clear, the values that are being reset are ONLY being used by the editor.
The seralizefield doesn't do anything in your ediator script. You need to apply those to you BezierPath script. Also I don't see where you are connecting those variables to the BezierPath script usually you would have something like ((BezierPath)target).varName. If those don't help is this object a prefab?
Answer by TonyLi · Aug 05, 2013 at 01:53 PM
As @Adamcbrz wrote, editor fields aren't serialized. Instead, save and load them from EditorPrefs.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111544im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why did the values i had set reset? 2 Answers
Value sometimes isn't updated. 1 Answer
Reset script variable values automatically? 2 Answers
Movement Issue: x value of object resets automatically 0 Answers
Progress lost after resetting game 2 Answers