- Home /
How to clear Undo-history for the target of a serializedObject?
Is it possible to do this? Say I have a ScriptableObject that needs some initialization that should not be reverted, can I tell Unity to ignore that changes when Ctrl+z? I tried Undo.ClearUndo, but that doesn't seem to do anything.
[MenuItem("Test/Create TestAsset")]
static void create()
{
SerializedObject propObject = new SerializedObject(ScriptableObject.CreateInstance<TestAsset>()));
TestAsset asset = AssetDatabase.CreateAsset(propObject.targetObject, "Assets/TestAsset.asset");
propObject.Update();
initializeAsset(propObject);
propObject.ApplyModifiedProperties();
//Clear undo-history for asset, so initialization can not be undone?
}
Anyone has an idea on this? I really need a solution for this as I can basically undo every single action performed on each object and sometimes undoing can break the objects (like after initialization, after saving etc.)
How about you just don't deal with SerializedObject/Property if you're not interested in Undo?
$$anonymous$$ost properties are private, and it would be great if I could avoid methods inside the object for that. So, are SerializedObjects so much connected to undoing that I need to get rid of using serializedObjects when I don't want to allow undoing changes?
Your answer
Follow this Question
Related Questions
Hooking Undo / RegisterUndo 0 Answers
What is the correct usage of RegisterCompleteObjectUndo/RegisterFullObjectHierarchyUndo 2 Answers
Destroying required components in editor 0 Answers
MonoBehaviour references are lost on Undo 0 Answers
Get SerializedProperty from outside class for use in popup (PropertyDrawer) 1 Answer