Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

EditorUtility.SetDirty

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство
public static function SetDirty(target: Object): void;
public static void SetDirty(Object target);

Параметры

target The object to mark as dirty.

Описание

Marks target object as dirty. (Only suitable for 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 when modifying objects in scenes. This function is due to be deprecated in future versions of Unity.

Prior to this change, the command could be used as part of an editor script to mark an object as dirty and therefore requiring a save. If this command was used on an object in the scene, the scene file itself was also marked dirty. Therefore if you used an editor script which modified scene objects, and which included this function, you would be prompted to save your work when closing the editor or switching to a different scene.

Since the change, when the command is used on a scene object, the scene itself is not marked as dirty. This means you use an editor script which modifies scene objects, and the script relies on “SetDirty” to implicitly mark the scene as requiring a save, this no longer works. If you close the editor or switch to a different scene without manually saving, Unity would not give a save prompt, and your changes would be lost with no warning.

Instead, your editor scripts should use should use the SerializedObject functions if modifying properties in a custom inspector, or use Undo.RecordObject in other types of editor scripts prior to making changes to the object. This will mark the object's scene as dirty and provide an undo entry in the editor.''

Generally, unless you have a good reason not to, you should provide undo steps in your editor scripts. However if your script modifies items within a scene and specifically do not want to add an undo entry for your modification, you can use EditorSceneManager.MarkSceneDirty.

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

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!

Unity internally uses the dirty flag to find out when assets have changed and need to be saved to disk.