Undo a instantiated gameObject Editor Script C#

I’m working on a Editor project that requires me to add game objects as children to a common parent object. This part I’ve accomplished but after i instantiate the game objects the Unity Undo (ctr z) wont remove the instantiated game object, thus my problem.
I’ve been looking through the Unity Undo documentation to allow me to use the Unity undo function to remove any misplaced game objects. So far Undo.RegisterSceneUndo seems to be the only solution. Unfortunately it is slow and causes some problems with other background functions of my script.

I have also considered somehow making the parent game object a SerializedObject hoping it would remember its previous state and children but have had little success. If anyone has any ideas on how to accomplish this please let me know.

Thanks in advance.

Stumbled across this problem myself use Undo.RegisterCreatedObjectUndo

For more detail check out step 14 of this awesome tutorial: