Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Resolved About createdelegate in b4?

Discussion in '2021.2 Beta' started by siliwangi, Jul 19, 2021.

  1. siliwangi

    siliwangi

    Joined:
    Sep 25, 2009
    Posts:
    303
    Hello, the following code below is working fine 2021.1 branch while on 2021.2b4 it failed at getRecordsInternalDelegate line 18:
    Code (csharp):
    1.  
    2.         public static void EnableUndoPro()
    3.         {
    4.             enabled = true;
    5.  
    6.             // Assure it is subscribed to all necessary events for undo/redo recognition
    7.             Undo.undoRedoPerformed -= UndoRedoPerformed;
    8.             Undo.undoRedoPerformed += UndoRedoPerformed;
    9.             EditorApplication.update -= Update;
    10.             EditorApplication.update += Update;
    11.             EditorApplication.playModeStateChanged -= PlaymodeStateChange;
    12.             EditorApplication.playModeStateChanged += PlaymodeStateChange;
    13.  
    14.             // Fetch Reflection members for Undo interaction
    15.             Assembly UnityEditorAsssembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
    16.             Type undoType = UnityEditorAsssembly.GetType("UnityEditor.Undo");
    17.             MethodInfo getRecordsInternal = undoType.GetMethod("GetRecordsInternal", BindingFlags.NonPublic | BindingFlags.Static);
    18.             getRecordsInternalDelegate = (Action<object, object>)Delegate.CreateDelegate(typeof(Action<object, object>), getRecordsInternal);
    19.  
    20.             // Create dummy object
    21.             if (dummyObject == null)
    22.                 dummyObject = new Texture2D(8, 8);
    23.  
    24.             // Setup default undo state and record
    25.             AssureRecords();
    26.         }
    27.  
    Anyone can point me at right direction? is it a bug or plain new C# standard?

    The full asset located in here.
     
  2. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    It's using private Unity APIs using reflection. Those APIs can change at any point and break code that's relying on them. The asset will have to be updated/adapted to work with the latest beta.
     
    PutridEx and siliwangi like this.
  3. Mannilie

    Mannilie

    Joined:
    Jan 29, 2016
    Posts:
    6
    Hey there,

    It appears that Unity has renamed their internal method 'GetRecordsInternal' to 'GetTimelineRecordsInternal'. Upon changing this, I've found those errors are non existent and UndoPro is able to obtain the correct records.
    upload_2021-8-1_11-6-53.png

    However, it has caused a new issue to un-earth itself. If you perform an Undo operation using Undo Pro, it now causes this error to occur:
    upload_2021-8-1_11-7-49.png

    I'm still looking into why this is happening but it's only a partial fix for now.
     
  4. Mannilie

    Mannilie

    Joined:
    Jan 29, 2016
    Posts:
    6
    Okay great news!

    This bug ended up being divided into two totally unrelated issues.
    1). Unity has moved their internal method 'GetRecordsInternal' to 'GetTimelineRecordsInternal'.
    To fix this, I simply put a version-specific wrapper around the effected area like so:
    upload_2021-8-1_12-44-30.png

    I ended up making a Pull Request to the repo for the developer so you can find the full code there.
    https://github.com/Seneral/UndoPro/pull/5

    2). The 'CheckConsistency: Restored Transform child parent pointer from NULL' error.
    After a long time of diangosing, I finally figured out what was causing this issue. It appears to only happen if users call 'Undo.RegisterCreatedObjectUndo' in any events other than EditorApplication calls. This is because Unity has restricted users to only call it during EditorApplication methods.
     
    Last edited: Aug 1, 2021
    LeonhardP and siliwangi like this.