Custom editor, float not saving when enter playmode.

Hi guys, I struggle with saving a float and a toggle and make them not reset when I enter play mode.
The float inspected in not part of the class and it is just a visual element for now. Whenever I enter play mode the value resets to 0.

    private bool ceva;
    float speed;
    public override void OnInspectorGUI()

        //EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((Bot)target), typeof(Bot), false);
        //foldout = EditorGUILayout.Foldout(foldout, "Behaviour Settings");
        //EditorPrefs.SetBool("foldout", foldout);

        Undo.RegisterCompleteObjectUndo(target, "Something changed");
        speed = EditorGUILayout.FloatField(speed);
        ceva = EditorGUILayout.Toggle(ceva);
        if (GUI.changed)

As you can see I tried the set dirty method but it does not work. I think because the float and the bool are not part of bot.cs than serializedObject.ApplyModifiedProperties will not change anything. I also checked out this post Unity editor not saving object changes - Questions & Answers - Unity Discussions and some dude suggested that I should use either undo system or serializedObject because set dirty is no longer active in unity 4.5 or so. I checked undo documentation and added the line before the actual var modification. Still nothing. Any help is appreciated! Thanks!

Hi @nickk2002 … Wait! You’re trying to show properties that don’t exist on some class?

I don’t think your problem is that the editor is not saving changes. The problem is it has nowhere to save them to. No measure you could take would rectify that beyond coding properties for your values.

When the game is run inspectors’ values are serialized and in order for that to happen you have to have real properties that exist behind the inspector - in your class code.

So anything you want to show in the inspector has to be saved somewhere and also be serializable if you want the same values to appear again.

I bet you get the same behavior whenever you recompile a script as well… and I’d be surprised if it remembers the cosmetic values when you click on one inspector and then back on the one with the problem.

if it is only “cosmetic for now” why not just put the few lines of code in your class to make them real properties?