Table of Contents

Class EditorUndoRedoManager

Manages undo history of scenes opened in the editor.

Inheritance
EditorUndoRedoManager

Remarks

EditorUndoRedoManager is a manager for UndoRedo objects associated with edited scenes. Each scene has its own undo history and EditorUndoRedoManager ensures that each action performed in the editor gets associated with a proper scene. For actions not related to scenes (ProjectSettings edits, external resources, etc.), a separate global history is used.

The usage is mostly the same as UndoRedo. You create and commit actions and the manager automatically decides under-the-hood what scenes it belongs to. The scene is deduced based on the first operation in an action, using the object from the operation. The rules are as follows:

  • If the object is a Node, use the currently edited scene;

  • If the object is a built-in resource, use the scene from its path;

  • If the object is external resource or anything else, use global history.

This guessing can sometimes yield false results, so you can provide a custom context object when creating an action.

EditorUndoRedoManager is intended to be used by Godot editor plugins. You can obtain it using get_undo_redo. For non-editor uses or plugins that don't need to integrate with the editor's undo history, use UndoRedo instead.

The manager's API is mostly the same as in UndoRedo, so you can refer to its documentation for more examples. The main difference is that EditorUndoRedoManager uses object + method name for actions, instead of Callable.

Methods

add_do_method(Object, StringName, ...)

Qualifiers: vararg

Register a method that will be called when the action is committed (i.e. the "do" action).

If this is the first operation, the object will be used to deduce target undo history.

void add_do_method(Object object, StringName method, ...)

Parameters

object Object
method StringName

add_do_property(Object, StringName, Variant)

Register a property value change for "do".

If this is the first operation, the object will be used to deduce target undo history.

void add_do_property(Object object, StringName property, Variant value)

Parameters

object Object
property StringName
value Variant

add_do_reference(Object)

Register a reference for "do" that will be erased if the "do" history is lost. This is useful mostly for new nodes created for the "do" call. Do not use for resources.

void add_do_reference(Object object)

Parameters

object Object

add_undo_method(Object, StringName, ...)

Qualifiers: vararg

Register a method that will be called when the action is undone (i.e. the "undo" action).

If this is the first operation, the object will be used to deduce target undo history.

void add_undo_method(Object object, StringName method, ...)

Parameters

object Object
method StringName

add_undo_property(Object, StringName, Variant)

Register a property value change for "undo".

If this is the first operation, the object will be used to deduce target undo history.

void add_undo_property(Object object, StringName property, Variant value)

Parameters

object Object
property StringName
value Variant

add_undo_reference(Object)

Register a reference for "undo" that will be erased if the "undo" history is lost. This is useful mostly for nodes removed with the "do" call (not the "undo" call!).

void add_undo_reference(Object object)

Parameters

object Object

clear_history(int, bool)

Clears the given undo history. You can clear history for a specific scene, global history, or for all scenes at once if id is EditorUndoRedoManager.INVALID_HISTORY.

If increase_version is true, the undo history version will be increased, marking it as unsaved. Useful for operations that modify the scene, but don't support undo.

var scene_root = EditorInterface.get_edited_scene_root()
var undo_redo = EditorInterface.get_editor_undo_redo()
undo_redo.clear_history(undo_redo.get_object_history_id(scene_root))

Note: If you want to mark an edited scene as unsaved without clearing its history, use mark_scene_as_unsaved instead.

void clear_history(int id, bool increase_version)

Parameters

id int
increase_version bool

commit_action(bool)

Commits the action. If execute is true (default), all "do" methods/properties are called/set when this function is called.

void commit_action(bool execute)

Parameters

execute bool

create_action(String, int, Object, bool)

Create a new action. After this is called, do all your calls to EditorUndoRedoManager.add_do_method, EditorUndoRedoManager.add_undo_method, EditorUndoRedoManager.add_do_property, and EditorUndoRedoManager.add_undo_property, then commit the action with EditorUndoRedoManager.commit_action.

The way actions are merged is dictated by the merge_mode argument. See MergeMode for details.

If custom_context object is provided, it will be used for deducing target history (instead of using the first operation).

The way undo operation are ordered in actions is dictated by backward_undo_ops. When backward_undo_ops is false undo option are ordered in the same order they were added. Which means the first operation to be added will be the first to be undone.

void create_action(String name, int merge_mode, Object custom_context, bool backward_undo_ops)

Parameters

name String
merge_mode int
custom_context Object
backward_undo_ops bool

force_fixed_history

Forces the next operation (e.g. EditorUndoRedoManager.add_do_method) to use the action's history rather than guessing it from the object. This is sometimes needed when a history can't be correctly determined, like for a nested resource that doesn't have a path yet.

This method should only be used when absolutely necessary, otherwise it might cause invalid history state. For most of complex cases, the custom_context parameter of EditorUndoRedoManager.create_action is sufficient.

void force_fixed_history

get_history_undo_redo(int)

Qualifiers: const

Returns the UndoRedo object associated with the given history id.

id above 0 are mapped to the opened scene tabs (but it doesn't match their order). id of 0 or lower have special meaning (see SpecialHistory).

Best used with EditorUndoRedoManager.get_object_history_id. This method is only provided in case you need some more advanced methods of UndoRedo (but keep in mind that directly operating on the UndoRedo object might affect editor's stability).

UndoRedo get_history_undo_redo(int id)

Parameters

id int

get_object_history_id(Object)

Qualifiers: const

Returns the history ID deduced from the given object. It can be used with EditorUndoRedoManager.get_history_undo_redo.

int get_object_history_id(Object object)

Parameters

object Object

is_committing_action

Qualifiers: const

Returns true if the EditorUndoRedoManager is currently committing the action, i.e. running its "do" method or property change (see EditorUndoRedoManager.commit_action).

bool is_committing_action

Events

history_changed

Emitted when the list of actions in any history has changed, either when an action is committed or a history is cleared.

signal history_changed

version_changed

Emitted when the version of any history has changed as a result of undo or redo call.

signal version_changed