Custom editor GUI resets

Hello everyone! So I know this has been posted quite a bit, but I am really at odds as to what is happening and why. I am trying to make a custom inspector for my game that will allow me to edit an AI state in my inspector. Currently, I am just trying to be able to assign an object to a field in the inspector. Now, I can assign and while that is good, it resets when I hit the Play button. I’ll post my code.

Thank you!

        [CustomEditor(typeof(AI.DecisionTree))]
        public class MyScriptInspector : Editor
        {
            [SerializeField] private AI.DecisionTree m_Script;

            [SerializeField] private Object source;

            public void OnEnable()
            {
                m_Script = (AI.DecisionTree)target;
            }

            public override void OnInspectorGUI()
            {
                EditorGUILayout.Space();
                DrawTextBox("Drag the AI Target GameObject here." +
                    " It will give its transform to all the AI states.", 0, 35, 0);

                // Drag and drop variable for the AI Pathfinding target
                source = EditorGUILayout.ObjectField(source, typeof(Object), true);

                EditorGUILayout.Space();

                if (GUI.changed)
                {
                    EditorUtility.SetDirty(target);
                }
            }
     }

MY DECISION TREE CLASS:

public class DecisionTree : MonoBehaviour
        {
            private Transform m_PathingTarget;
            [SerializeField] private List<AIStates.IAIState> m_StateList;
            [SerializeField] private AIStates.IAIState m_CurrentState;

            [SerializeField] private AIStates.SeekState m_SeekState;
            [SerializeField] private AIStates.PatrolState m_PatrolState;
            [SerializeField] private AIStates.ChaseState m_ChaseState;

            
            void Awake()
            {
                // Create out new AI State list!
                m_StateList = new List<AIStates.IAIState>();

                // Add the states to the AI list.
                m_StateList.Add(m_SeekState);
                m_StateList.Add(m_PatrolState);
                m_StateList.Add(m_ChaseState);

                m_PatrolState.InitState();

                m_CurrentState = m_PatrolState;
            }

            // Use this for initialization
            void Start()
            {

            }

            void OnValidate()
            {
                // Debug.Log("ewoijfewnewofnewoif");
            }

            public AIStates.PatrolState GetPatrolState()
            {
                return m_PatrolState;
            }

            public ReadOnlyCollection<AIStates.IAIState> m_AIStateList
            {
                get
                {
                    return m_StateList.AsReadOnly();
                }
            }

            void SetNewState(AIStates.IAIState node)
            {

            }

            // Update is called once per frame
            void Update()
            {
                m_CurrentState.ManualUpdate();
            }
        }

Hi @Spartiate0033! From the looks of your script, you want to actually be setting the value of the m_PathingTarget field on your DecisionTree script. If that’s it, you don’t even need a custom editor here. If you add the SerializeField attribute to the m_PathingTarget field on your DecisionTree script it should automatically appear in the inspector.