Search Unity

Rename Undo step after CollapseUndoOperations

Discussion in 'Scripting' started by TheRealBanbury, Dec 25, 2013.

  1. TheRealBanbury

    TheRealBanbury

    Joined:
    Dec 15, 2013
    Posts:
    248
    Hi,
    I'm trying to add undo support to a complex multistep operation. I want all steps to be undone at the same time. CollapseUndoOperations does this essentially. But there's no way to rename the last undo step. So after the collapse the undo menu says 'Delete object', which is not appropriate at all. Is there a way to choose the name of the undo operation?

    Greetings

    Banbury
     
  2. scanzy

    scanzy

    Joined:
    Mar 14, 2014
    Posts:
    9
    Try this:

    Code (CSharp):
    1.  
    2.             //set undo name
    3.             Undo.SetCurrentGroupName("Undo message here");
    4.  
    5.             //your undo operations here
    6.             Undo.RecortObject(myObj, "");
    7.             Undo.DestroyObjectImmediate(myObj2);          
    8.             ....
    9.  
    10.             //collapses all undos into one
    11.             Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
    12.  
    This is working for me in unity 5.6 beta

    Note that you set the undo operation name with Undo.SetCurrentGroupName (before recording objects).
    Messages set in RecordObject, and all other Undo recording functions will be ignored
     
  3. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    798
    I know this resurrected an old request, but really helped me out, so thank you!
     
    simple421 and scanzy like this.