Unity5.3之后EditorUtility.SetDirty使用问题

几天前,UE说有时候他们在编辑器内改了prefab但是没有保存,我查了一下,发现项目中Editor中用到了这个接口用来将Scene SetDirty,之前很多地方都是这样用,也没觉得有什么问题,后来仔细查了一下,发现在Unity5.3之后,这个接口使用的场景变了,具体可以在Unity的官方文档中看到:地址

具体如下:

EditorUtility.SetDirty

Marks target object as dirty. (Only suitable for non-scene objects).(将目标Object标记为Dirty(仅适用于non-scene objects))

NOTE: ''Prior to Unity 5.3, this was the primary method of marking objects as dirty. From 5.3 onwards,
with the introduction of Multi-Scene Editing, this function should no-longer be used for modifying objects in scenes. Instead, you should use Undo.RecordObject prior to making changes to the object.
This will mark the object's scene as dirty and provide an undo entry in the editor.''
在Unity 5.3之前,这是将对象标记为脏的主要方法。 
从5.3开始,随着多场景编辑的引入,此功能不应再用于修改场景中的对象。
相反,在对对象进行更改之前,应该使用Undo.RecordObject。 
这会将对象的场景标记为脏,并在编辑器中提供撤消条目

If you are modifying files within a scene and specifically do not want to add an undo entry for your modification, you should use EditorSceneManager.MarkSceneDirty
如果你在场景中修改文件,并且不希望为修改添加撤消条目,则应该使用EditorSceneManager.MarkSceneDirty


If you are using a custom editor to modify serialized properties on a component or an asset, you should be using [pSerializedObject.FindProperty]], SerializedObject.Update, EditorGUILayout.PropertyField, and SerializedObject.ApplyModifiedProperties. This will mark the modified object as 'dirty' and create Undo states for you.

如果你使用自定义编辑器修改component或asset的序列化属性,应该使用[pSerializedObject.FindProperty]],SerializedObject.Update,EditorGUILayout.PropertyField和SerializedObject.ApplyModifiedProperties。 这会将修改的对象标记为“脏”并为你创建撤消状态。

Therefore the only remaining situation in which you should use this function is if you are modifying non-scene objects via some other means, and specifically do not want create an undo entry for your modification. This is rare, and unless you're very sure about requiring this, you probably shouldn't be using this command!
因此,你应该使用此功能的唯一剩余情况是,你是否通过其他方式修改非场景对象,并且不希望为修改创建撤消条目。 这很少见,除非你确定要求这样做,否则你可能不应该使用这个命令!

也就说这个接口在Unity5.3之后被改了,项目中一些代码是老代码,没有改成新的接口,出现了这个问题