How to get information about an undo/redo that happened in the level-editor viewport.

I noticed that this post is on the first page on google when you search for ‘PostUndoRedo’, so here is a solution that will allow you to listen to an undo or redo specifically.

While this does not give any information about the operation itself and what has changed, it does make it much easier to create your own system that needs to react to one of these specifically.

Solution:

Step 1: derive your class from ‘FEditorUndoClient’.

class UClassName : public FEditorUndoClient

Step 2: override the ‘PostUndo’ and ‘PostRedo’ that are defined on ‘FEditorUndoClient’.

protected:
	virtual void PostUndo(bool bSuccess) override;
	virtual void PostRedo(bool bSuccess) override;

Step 3:
Register your derived class for the undo/redo during its initialization.

GEditor->RegisterForUndo(this);

And optionally call ‘UnregisterForUndo’ during deinitialization of your class.

This should’ve been properly documented instead of stumbling across the solution accidentally when looking through the engine code.

3 Likes