- Home /
Undo.RegisterFullObjectHierarchyUndo not working
I have a custom editor that let's be update the layout of some UI objects, I want to be able to undo this operation if I don't like it but I can't get it to record.
My component is set up like so: Main Component (that the custom editor is editing) > Child Content (like the Scroll Rect) > Child Items (children of the content). The Child Items & the Content are what's being modified.
Currently my code is looking like this:
public override void OnInspectorGUI()
{
MainComponent main = (MainComponent)target;
//custom inspector stuff
if(GUILayout.Button("Update"))
{
Undo.RegisterFullObjectHierarchyUndo(main.Content.gameobject, "Layout Update");
main.UpdateLayout();
}
}
This does create an undo step under Edit > Undo. The undo step just doesn't revert anything. If anyone knows what I'm doing wrong/know something to help I would love to hear it! Ty!
Answer by Bunny83 · Mar 01, 2018 at 03:11 AM
All "Register" methods in the Undo system have to be called right before you apply any changes to your object. You can not group multiple changes into a single undo step if those changes are not applied from the same event (i.e a mouse down / mouse up event).
Your answer
Follow this Question
Related Questions
How do I replicate brushes selection in Unity terrain component? 0 Answers
Unity 5.1.1f1: Redo operation in custom editor causes some sort of corruption. 1 Answer
How to provide undo for EditorScript changes to a prefab? 1 Answer
Edit an object in isolation quickly, as in the new Prefab Mode 0 Answers