How to deal with object deletion Undo states and variables referencing the objects involved?

This is an editor scripting question. Say I have a List (edit - Built in Array) of GameObjects. I have the user of my editor extension delete some of them from the scene. I register that deletion with the Undo system by using: Undo.DestroyImmediate(MyObject). At the time of deletion I also remove the objects from my List (edit - Built in Array). When the user then presses ‘Undo’, the objects are re-created by Unity’s built in processes. How can I restore them to my list(edit - Built in Array)?

I think this is relevant to this question:

Here are just a few thoughts @SebastianPatric:

  1. Implement your own undo/redo system
    in your editor. So you will need to
    add Undo/Redo buttons to your editor
  2. Make your base items of the list/array seriliazable.
  3. Define a custom class - to record the actions
    done in your editor window - with
    some actions like create,delete etc (Enums?),
    with each action taking in the
    relevant info (A deep copy of the
    instance of your list item - this could be a serialized version of the instance?).
  4. Define a stack of of type action in the
    custom class - This could be a static variable of the custom class. Whenever an action is taken in your editor, create the appropriate action object and push it to the stack.
  5. Add Undo/Redo functions
    linked to the buttons in the editor
    with their implementation for the
    Undo/Redo the action.

You most likely do an undo on a database or file. You have to repopulate the array from data source after undo.