Be able to use Ctrl + Z and Ctrl + Y on custom Undo system

Hey guys,

I’m creating my custom Undo system to my editor tool and I’ve hit a roadblock.

I want to be able to use Ctrl + Z and Ctrl + Y, since those are the key shortcuts everyone is accustomed to. The problem is that they are directly connected to Unity’s own Undo ( which I don’t want to use ).

I’m catching the event over my EditorWindow OnGui() method but no matter what I do Unity Undo always kicks in.

I’ve tried using both the ValidateCommand and ExecuteCommand events, setting their Type to Ignore, even resetting the commandName contents but its no use.

Something like this:

if( Event.current.type == EventType.ValidateCommand ||
    Event.current.type == EventType.ExecuteCommand )
{
    if( Event.current.commandName.Equals( "UndoRedoPerformed" ) )
    {
        Event.current.type = EventType.Ignore;
        Event.current.commandName = string.Empty;
        Event.current.Use();
    }
}

I’m starting to question myself if this is even possible.

Does anyone knows if this can be achievable, to stop the undo event to be propagated?

Thanks for the help.

Just a courtesy reminder, you can hook into the undo system to register specific objects, properties and changes that you want to be tracked

This is going to be entirely dependent on Unity’s internals, and hence subject to future changes (and even different behavior on different editor platforms) unless they explicitly provide an API to list yourself as the first receiver for specific key combinations.