Symptoms:
- I modify a property via the scripting API.
- The scene is not made dirty.
Cause:
Scripting APIs do not use the undo mechanism nor mark the scene dirty by default. One can, however, enforce these behaviors.
Resolution:
There are two different options for solving this:
Option 1:
If you have access to the object itself, you can use the Undo.RecordObject method before setting the property from the script.
Undo.RecordObject (myGameObject.transform, "Zero Transform Position"); myGameObject.transform.position = Vector3.zero;
An example that shows how the scene is marked dirty with Undo.RecordObject is attached at the end of this article.
Option 2:
One can also mark the scene as dirty manually using:
EditorSceneManager.MarkSceneDirty
after setting a property from script for example:
LightmapEditorSettings.bakeResolution = 14; EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
More information