Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Any ways to workaround the slow Undo API?

Discussion in 'Scripting' started by bitinn, Apr 16, 2020.

  1. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    958
    Hi folks,

    I might be barking at the wrong trees here, but I find Undo class not terribly great at handling a large number (1000+) of Undo items being added quickly.

    For example, RegisterCreatedObjectUndo and DestroyObjectImmediate are quite slow if we are trying to record every single of these items.

    Are there ways to do these in batch, so that we have less bottleneck on Undo? I know it will still be slow to serialize so much data, but at the moment Undo is 5~10 times slower than anything else in my script.

    Thx.
     
  2. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    958
    I should note that we obviously don't need to restore each individual items, we want to undo them in batch, we use CollapseUndoOperations at the end already.
     
  3. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    958
    And let's assume all the instantiated game objects are appended to a single parent game object, so maybe if we can just restore the parent game object we will be fine?
     
  4. Stacklucker

    Stacklucker

    Joined:
    Jan 23, 2015
    Posts:
    82
    This has been the my pain over the last couple months.
    I'm glad I'm not suffering alone, but sad that there still seems to be no solutions.

    The icing on the cake is that Unity says in their official guidelines for Unity Asset Store tools that editor tools are required to implement Undo functionality. Funny because implementing it renders lots of my tools utterly un-usable in case as you have described, e.g. instantiating hundreds of objects.

    I'm making a new post about this right now (so perhaps check my history), but I found out that editor performance gets worse over time the more calls you make to the Undo API until you clean the history with Undo.ClearAll().