Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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

Sumbission failed

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

Close

Cancel

public static function SetDirty(target: Object): void;
public static void SetDirty(Object target);
public static def SetDirty(target as Object) as void

Description

Marks target object as dirty.

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

E.g. if you modify a prefab's MonoBehaviour or ScriptableObject variables, you must tell Unity that the value has changed. Unity builtin components internally call SetDirty whenever a property changes. MonoBehaviour or ScriptableObject don't do this automatically so if you want your value to be saved you need to call SetDirty.

	#pragma strict
	// This example shows a custom inspector for an
	// object "MyPlayerEditor", which has two variables, speed and ammo.
	@CustomEditor(MyPlayer)
	class MyPlayerEditor extends Editor {
		function OnInspectorGUI()
		{
			var targetPlayer = target as MyPlayer;
			EditorGUILayout.LabelField ("Some help", "Some other text");

GUI.changed = false; targetPlayer.speed = EditorGUILayout.Slider ("Speed", targetPlayer.speed, 0, 100); if (GUI.changed) EditorUtility.SetDirty(targetPlayer); } }