Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CollapseUndoOperations(int)

Collapses all undo operations down to group index together into one step.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor
public static void CollapseUndoOperations(int groupIndex)

Parameters

groupIndex

The group index to collapse undo operations to.

Remarks

The current group index automatically increases on mouse down, by clicking on menu items, and other operations. This method collapses all undo operations with group indices above the provided group index to that group index. This is used by the color picker to combine all color modifications into a single step once the color picker is closed, while they are seperate operations when the color picker is still open.

Examples

using UnityEditor;using UnityEngine;public class ResetPositionForSelectedGameObjectsExample : MonoBehaviour{ [MenuItem("MyMenu/Reset Positions of Selected GameObjects")] static void ResetPositionForSelectedGameObjects() { Undo.SetCurrentGroupName("Zero out selected gameObjects"); int group = Undo.GetCurrentGroup(); Undo.RecordObjects(Selection.transforms, "transform selected objects"); foreach (Transform t in Selection.transforms) { t.position = Vector3.zero; } Undo.CollapseUndoOperations(group); }}