Version: 5.3 (switch to 5.4b)
IdiomaEnglish
  • C#
  • JS

Idioma de script

Selecciona tu lenguaje de programación favorito. Todos los fragmentos de código serán mostrados en este lenguaje.

EditorUtility.SetDirty

Sugiere un cambio

¡Éxito!

Gracias por ayudarnos a mejorar la calidad de la documentación de Unity. A pesar de que no podemos aceptar todas las sugerencias, leemos cada cambio propuesto por nuestros usuarios y actualizaremos los que sean aplicables.

Cerrar

No se puedo enviar

Por alguna razón su cambio sugerido no pudo ser enviado. Por favor <a>intente nuevamente</a> en unos minutos. Gracias por tomarse un tiempo para ayudarnos a mejorar la calidad de la documentación de Unity.

Cerrar

Cancelar

Cambiar al Manual
public static function SetDirty(target: Object): void;
public static void SetDirty(Object target);

Parámetros

target The object to mark as dirty.

Descripción

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.