I’ve written plenty of editor scripts before, but now I’ve gotten hung up. What am I doing wrong?
Relevant snippets:
Compensation.cs
public class Compensation : MonoBehaviour
{
public float maxDistance;
}
Editor/DebugCompensation.cs
[CustomEditor(typeof(Compensation))]
public class DebugCompensation : Editor
{
public override void OnInspectorGUI()
{
Compensation myTarget = (Compensation)target;
//...other stuff
myTarget.maxDistance = EditorGUILayout.FloatField(
"Max Compensation", myTarget.maxDistance);
}
}
Now, in the editor, I have the field “Max Compensation”. I can change it in the editor, but when I click play it sets the value to 1 (regardless of what I enter.) If I change that field while it’s running, it changes the value fine.
I’ve already combed through anything that references “maxDistance” to make sure I’m not setting it’s value anywhere else, and I’m not. Any ideas on what’s going on?