Version: 2019.2
LanguageEnglish
  • C#

EditorUtility.SetDirty

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static void SetDirty(Object target);

Parameters

targetThe object to mark as dirty.

Description

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 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.''

Use EditorSceneManager.MarkSceneDirty when modifying files within the Scene with no added undo entries.

Also use SerializedObject.FindProperty, SerializedObject.Update, EditorGUILayout.PropertyField, and SerializedObject.ApplyModifiedProperties when using a custom editor to modify serialized properties on a component or an asset. When modified the component or asset will be marked as 'dirty' and have a created Undo state.

The only remaining use (which is used rarely) happens if a non-scene object is modified with other means and with no added undo entry. Use of this approach is unlikely.

Unity uses the dirty flag internally to find changed assets that must be saved to disk.

See Also: GetDirtyCount, IsDirty.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961