Public variables set with custom editor buttons reset to prefab values on play?

I am working on a 2D platformer and have a script for moving objects from one Vector2 position to another (simply titled “MovingObject”). I have 2 public Vector2 values for the 2 positions I want the objects to move between (“minPos” and “maxPos”). To make it easier to set the positions of these objects, I have created an editor script with custom buttons for setting these values.

The problem with this is that, when setting values using the custom buttons in objects placed from prefabs, the prefab connections of the values are not broken. As a result, the values reset to what they are defined as in the prefab (all 0) when I click play. The connections are broken when I edit each value manually, but having to do this with each object would make things far more tedious for me.

Here is my editor script:

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(MovingObject))]
public class MovingObjectEditor : Editor {

	public override void OnInspectorGUI(){
		DrawDefaultInspector();

		MovingObject mo = (MovingObject)target;
		
		if (GUILayout.Button ("Set Min Pos"))
			mo.SetMinPos ();
		if (GUILayout.Button ("Set Max Pos"))
			mo.SetMaxPos ();
		if (GUILayout.Button ("Move To Min"))
			mo.MoveToMin ();
	}
}

These are the 3 functions referred to in the editor script:

	public void SetMinPos() {
		minPos = transform.position;
	}
	public void SetMaxPos() {
		maxPos = transform.position;
	}
	public void MoveToMin() {
		transform.position = minPos;
	}

I have looked at several solutions to this problem, but have not gotten any to work properly. Any help is appreciated.

This was a common issue I was able to fix this issue by:

  1. Ensuring game is not running
  2. When modifying prefab, if your
    modifying the one in the scene, you
    need to drag it to your project
    assets prefab to update it
  3. Drag the prefab from your project to said script