Unity Editor Script Changes To Scene Not Recognized

Sorry I can’t think of how to phrase this better. The issue I am having is that when I open up multiple unity scenes and make terrain changes to change the layer and set trees to preserve prototype layer via an editor script, unity does not show the asterisk next to the scene name allowing me to save changes made. I’ve verified that the script is working, changes appear in editor, but unity save system doesn’t recognize any changes have been made. If I manually change the layers in the editor, it works. I can’t manually change these settings though because of the large number of objects I am working with. Here’s the code I am using.

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections.Generic;

public class changeTerrainLayer : EditorWindow 
{		
    GameObject[] selectedGameObjects;
    [MenuItem("Berna Systems/Terrain/Change terrain layer")]
	static void Init()
    {
        changeTerrainLayer window = (changeTerrainLayer)EditorWindow.GetWindow(typeof(changeTerrainLayer));
		
       	window.minSize =  new Vector2( 100f,100f );		
		window.maxSize =  new Vector2( 200f,200f );		
		
		window.autoRepaintOnSceneChange = true;
       	window.title = "Change Terrain Layers";
       	window.Show();
	}

    void OnGUI()
    {
        selectedGameObjects = Selection.gameObjects;

        if (selectedGameObjects == null)
        {
            Debug.LogWarning("No terrain was selected");
            return;
        }

        else if (GUILayout.Button("Change Layer"))
        {
            foreach(GameObject terrainGameObj in selectedGameObjects)
            {                
                terrainGameObj.GetComponent<Terrain>().preserveTreePrototypeLayers = true;
                terrainGameObj.layer = LayerMask.NameToLayer("Terrain");
            }
		}														
	}	
}

Take a look at this.

MarkSceneDirty

Hope this helps,
-Larry