So, our team has made a couple of custom editor scripts to try and make some of our tools more usable. They work for the most part, but we’ve found an interesting side-effect. As soon as there’s a custom script for any object, the unity scene gets set to ‘dirty’, even when no changes have been made. The only way to avoid getting the save notification is to not click in the scene editor at all, and sometimes that doesn’t even work.
The Undo dialog given is ‘Change Selection’, but with objects not using custom editors, this does not flag the scene as dirty. Is there a way to fix this behaviour? It’s not necessarily breaking any scenes, but it’s very irritating to get the save dialogue constantly.
I’ve included the simplest/shortest version of our editor scripts below.
#pragma strict
@CustomEditor (ConveyorController)
class ConveyorControllerEditor extends Editor {
function OnSceneGUI() {
Undo.SetSnapshotTarget(target, "Altered Conveyor");
var script:ConveyorController = target as ConveyorController;
var pointA:Vector3 = script.GetPointA();
var pointB:Vector3 = script.GetPointB();
script.transform.position = (pointA + pointB) / 2;
var A:Vector3 = Handles.PositionHandle(pointA, Quaternion.identity);
var B:Vector3 = Handles.PositionHandle(pointB, Quaternion.identity);
var swap:float = 0;
//A is always left of B (smaller val)
if(A.x > B.x)
A.x = B.x;
if (GUI.changed) {
EditorUtility.SetDirty(target);
script.SetPointA(A);
script.SetPointB(B);
}
if(Input.GetMouseButtonDown(0)) {
Undo.CreateSnapshot();
Undo.RegisterSnapshot();
}
}
}