- Home /
How do you emulate the undo system with custom inspectors?
In the Unity Editor, any changes you make in the default Inspectors can be undone, nicely. I want to do this with custom inspectors too. I'd just like any code example; I didn't have luck with whatever I tried last time.
Hey Jessy, I started a bounty on my undo question (http://answers.unity3d.com/questions/44888/how-to-correctly-register-undos-in-custom-inspector-within-oninspectorgui)... Hope someone will know a valid answer :P
Hey Jessy, with some help I found a fully working solution :) Look at my original answer for the right code (I edited it and added an example). The given answers weren't correct, but helped me a lot.
Seems the pages have gone missing (due to software update??)
Could this be the page mentioned with Danele's answer: http://answers.unity3d.com/questions/50954 ????
Answer by Statement · Apr 02, 2011 at 04:25 PM
http://answers.unity3d.com/questions/45880/ Does that help?
That helps the question you're helping me with tonight*, and you helped $$anonymous$$e come to the answer for the question in her comments above, which was most enlightening. Thanks. *http://answers.unity3d.com/questions/53143
Seems the pages have gone missing (due to software update??)
Could this be the page mentioned with Danele's answer: http://answers.unity3d.com/questions/50954 ????
Unfortunately you have to use the full url of the question. It's a pity that you can't view the question just by id...
http://answers.unity3d.com/questions/50954/how-to-correctly-register-undos-in-custom-inspecto.html
Answer by burnumd · Mar 04, 2011 at 09:10 PM
What did you do last time? I've successfully used features of the Undo class in inspectors in the past. What you're attempting to undo influences how I'd recommend you use it (and any code samples I could offer), but the class documentation is robust enough to tell you when to use RegisterUndo and RegisterSnapshot. If that's what you were using before, be sure to let everyone know and maybe someone can come up with an alternate solution.
ETA: Here's an example of how I've used Undo.RegisterUndo in an inspector before:
GameObject tempObject = (GameObject)EditorGUILayout.ObjectField (((MyClass)target).myObject, typeof(GameObject));
if (tempObject != ((MyClass)target).myObject)
{
Undo.RegisterUndo (new Object[1] { target }, "Set Object");
((MyClass)target).myObject = tempObject;
}