How to Undo a lot of created objects at once? [Solved]

Hello everybody and good day.


I have a little problem trying to make an Undo step after creating a bunch of objects using a for loop method (in edit not play), I read the docs about it but honestly I don’t understand how that could be done or even if that it’s possible.


I know that undo a group of selected objects can be done after deletion but not at creation, so, any one could help me to resolve this?, I’m not an experienced programmer, but I can understand many things about coding inside Unity (except this one about Undo group things).

After some API study, I found the solution by my self.
In the 2018.x version, to make an undo of more than 1 object, only have to do this:

Undo.RecordObject(null, "Base Undo");
int undoID = Undo.GetCurrentGroup();
//Sample---
for (int i = 0; i < 10; i++){
    GameObject go = Instantiate(original);
    Undo.RegisterCreatedObjectUndo(go, "New Undo");
    Undo.CollapseUndoOperations(undoID);
}

With this, can be undone many objects at once.