docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class UndoBlock

    Represents a series of object actions as a single undo-operation.

    Inheritance
    object
    UndoBlock
    Implements
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.XR.CoreUtils
    Assembly: Unity.XR.CoreUtils.dll
    Syntax
    public class UndoBlock : IDisposable
    Remarks

    UndoBlock methods work in both Edit mode and Play mode. In Play mode undo-operations are disabled. This class mirrors the normal functions you find in the Undo class and collapses them into one operation when the block is complete.

    Examples

    Proper usage of this class is:

    using (var undoBlock = new UndoBlock("Desired Undo Message"))
    {
        undoBlock.yourCodeToUndo()
    }

    Constructors

    UndoBlock(string, bool)

    Initialize a new UndoBlock.

    Declaration
    public UndoBlock(string undoLabel, bool testMode = false)
    Parameters
    Type Name Description
    string undoLabel

    The label to apply to the undo group created within this undo block.

    bool testMode

    Whether this is part of a test run.

    Methods

    AddComponent<T>(GameObject)

    Adds a component to the game object and registers an undo operation for this action.

    Declaration
    public T AddComponent<T>(GameObject gameObject) where T : Component
    Parameters
    Type Name Description
    GameObject gameObject

    The game object you want to add the component to.

    Returns
    Type Description
    T

    The new component.

    Type Parameters
    Name Description
    T

    The type of component you want to add.

    Dispose()

    This code added to correctly implement the disposable pattern.

    Declaration
    public void Dispose()

    Dispose(bool)

    Dispose of this object.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    Whether to cleanup this object's state.

    RecordObject(Object)

    Records any changes done on the object after the RecordObject function.

    Declaration
    public void RecordObject(Object objectToUndo)
    Parameters
    Type Name Description
    Object objectToUndo

    The reference to the object that you will be modifying.

    RegisterCreatedObject(Object)

    Register undo operations for a newly created object.

    Declaration
    public void RegisterCreatedObject(Object objectToUndo)
    Parameters
    Type Name Description
    Object objectToUndo

    The object that was created.

    SetTransformParent(Transform, Transform)

    Sets the parent transform of an object and records an undo operation.

    Declaration
    public void SetTransformParent(Transform transform, Transform newParent)
    Parameters
    Type Name Description
    Transform transform

    The Transform component whose parent is to be changed.

    Transform newParent

    The parent Transform to be assigned.

    Implements

    IDisposable
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)