- Home /
Can you use a more performant undo function than RegisterSceneUndo with DestroyImmediate?
The documentation states that Undo.RegisterSceneUndo is the slowest way to undo an operation, and that makes sense. However, it doesn't suggest an alternative, when the operation involves a DestroyImmediate(); call. I couldn't get a regular RegisterUndo to work, because the objects that I put into the objectsToUndo array were no longer available after the operation ended.
Answer by Joachim Ante · Apr 03, 2010 at 05:52 PM
Currently the only way to register an undo function that revert object deletion is through RegisterSceneUndo.
Internally we usually use this function only if it is not possible to implement it in another way, for example in this very case.
Answer by Cyclops · Apr 03, 2010 at 05:00 PM
What kinds of Objects were you putting into RegisterUndo? Because looking at the description, it says,
"Note that only the actual objects passed as parameters are saved. For example, passing a game object will not save all its components or child objects. If you need to save the state of an entire game object, you can use EditorUtility.CollectDeepHierarchy on the game object to get all the objects that it contains and pass all those objects as objects to undo."
I haven't looked at Undo before, but it could be that your top-level Object isn't available because all of its components are gone (making it no longer functional). You may need to save everything, as noted above.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141910im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Undo.RecordObject isn't working. 7 Answers
Undo.RegisterFullObjectHierarchyUndo not working 1 Answer
Does Undo.RecordObject support marking ScriptableObjects dirty? 2 Answers
Hooking Undo / RegisterUndo 0 Answers
Undo in Editor function 0 Answers