Editor Script does not save changes

I have created an Script to connect the tiles that are near in my game. It works when I’m working on the editor but when I run the game or close the program, all the changes are erased. How to save the changes?

using UnityEngine;
using UnityEditor;
public class ConnectTilesButton
	[MenuItem("Utils/Connect Tiles")]
	public static void ConnectTiles()
		Tile[] tiles = Resources.FindObjectsOfTypeAll<Tile>();

		for (int i = 0; i < tiles.Length; i++)
			Undo.RecordObject(tiles*, "removeTile");*

_ tiles*.PositionsConected.Clear();_

* for (int i = 0; i < tiles.Length; i++)*
* {*
_ Undo.RecordObject(tiles*, “addTile”);
for (int j = 0; j < tiles.Length; j++)
if (tiles _!= tiles[j] || tiles.PositionsConected.Contains(tiles[j]))
if (Vector3.Distance(tiles.gameObject.transform.position, tiles[j].gameObject.transform.position) <= 1.1f)
Undo.RecordObject(tiles, “addTile”);

* {
Undo.RecordObject(tiles, “removeTile”);
if (tiles.PositionsConected.Contains(tiles[j]))

I might be a bit late with answer, but in case some1 also will face same problem, you should firstly serialize object that you want to make changes on:

    var serialisedObj = new SerializedObject(objectYouWantToChange);
    //finding property you want to modify, in this case its vector3, 
    //could be either all custom classes
    serialisedObj.FindProperty("myVectorPropertyToModify").vector3Value = newValue;
    //will apply all changes to your object in scene

Hope it will help someone