Undo.RecordObject doesn't work when swapping arrays

I’m writing an audio editor and I have a visual timeline in an Editor Window that lets me edit audio sources and clips.
In OnGUI I call:
Undo.RecordObject(sequence.blender, “Edit Tracks”);
Before I run any code for editing the tracks and this works perfectly - when I hit undo, it works for all kinds of changes I’ve made to the timeline except for:
- Deleting
- Adding new objects

Since I’m using arrays, deleting and adding clips works by allocating a new array and writing to it:

public void RemoveClip(int index)
            {
                if (index < 0 || index >= clips.Length) throw new UnityException("Clip " + index + " does not exist");
                clips[index].Destroy();
                BlendClip[] newClips = new BlendClip[clips.Length - 1];
                for (int i = 0; i < clips.Length; i++)
                {
                    if (i == index) continue;
                    if (i < index) newClips[i] = clips[i];
                    if (i > index) newClips[i - 1] = clips[i];
                }
                clips = newClips;
            }

Does anyone have any idea how I can record this as an undo action? Changes to properties of array elements get recorded well but not this.

you need to destroy objects with Undo.DestroyObjectImmediate
you need to create objects with Undo.RegisterCreatedObjectUndo
not sure about the array, maybe try Undo.RegisterCompleteObjectUndo

lots of other methods here: Unity - Scripting API: Undo

Hi, this is what I do to destroy the audio sources themselves and this is inside clips[index].Destroy();
So basically, when I delete an object I call Undo.RecordObject and I remove the array antry. Then inside Destroy I have Undo.DestroyObjectImmediate for the source. And what happens is: when I hit Ctrl + Z, only the audio source gets brought back in the scene but not the array entry. So Undo.DestroyObjectImmediate definitely works but RecordObject doesn’t work when an array element is added or removed.