I am working with a tool script which extends Resource, so the UndoRedo shouldn’t be tied to the current scene. I have gotten a workaround solution to work, which is getting a dummy EditorPlugin’s UndoRedo and freeing the dummy immediately:
var dummy_ep := EditorPlugin.new()
var undo_redo := dummy_ep.get_undo_redo()
dummy_ep.free()
I wanted to ask, is there a more straight forward way to gain access to the global UndoRedo?
If there really is no way in GDscript to fetch the global UndoRedo then I’ll probably draft a proposal to the github and see if anyone sees it as a worthwhile enhancement.
EditorInterface is only available in the editor and won’t work at runtime. If the script needs to work at runtime you can get it using Engine.get_singleton()
For example:
extends Resource
func do_something() -> void:
if Engine.is_editor_hint():
var editor_interface = Engine.get_singleton("EditorInterface")
var undo_redo = editor_interface.get_editor_undo_redo()
# ...