Solved
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).
Answer by ArturoSR · Apr 03, 2019 at 02:18 AM
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.
In version 2018.4.13f1 when this line is executed
 Undo.RecordObject(null, "Base Undo");
I get this error
 Undo object may not be null.
Also you're using Undo.CollapseUndoOperations(undoID) every time you create a new object.
I think this the correct way
 Undo.IncrementCurrentGroup();
 Undo.SetCurrentGroupName("Undo name");
 var undoGroupIndex = Undo.GetCurrentGroup();
 
 for (int i = 0; i < 10; i++)
 {
    GameObject go = Instantiate(original);
    Undo.RegisterCreatedObjectUndo(go, "");
 }
 
 Undo.CollapseUndoOperations(undoGroupIndex);
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                