The description here seems very clearly, but my test code is not working. The undo entry “My Transaction Test” is in the Undo-History, but it is not undoing the translation. Anyone can help?
import unreal
actors = unreal.EditorLevelLibrary.get_selected_level_actors()
location = actors[0].get_actor_location()
with unreal.ScopedEditorTransaction("My Transaction Test") as trans:
location.z += 28
actors[0].set_actor_location(location, False, True)
I seem to only get AttributeErrors that unreal is missing the ScopedEditorTransaction. Are there even more plug-ins required beyond the “Editor Scripting Utilities” and “Python Editor Script Plugin”?
world = unreal.EditorLevelLibrary.get_editor_world()
it = unreal.SelectedActorIterator(world)
with Undo('UndoTest', unreal.Text("My Undo Test")) as undo:
for actor in it:
unreal.SystemLibrary.create_copy_for_undo_buffer(actor)
unreal.SystemLibrary.transact_object(actor)
actor.add_actor_local_offset(
offset,
sweep=False,
teleport=True
)
In this situation (since you’re not setting properties directly via set_editor_property) you need to call modify on the object before you change it, as this notifies the transaction system that it is going to change and needs to be tracked. We could perhaps do this automatically when calling non-pure methods on an object from Python.
Which version of UE4 are you using. I think this was only added in 4.21.
I don’t know why that would be. It shows up fine for me in 4.22, and is defined in PyEditor.cpp (which is a core PythonScriptPlugin file, so there’s nothing external you could have disabled).
Its been some time since this was asked, but its still a problem. I found this post, so this is for others that stumble upon it as well.
Here is my work around:
The help() doc for the class has the list of the properties. Each class property is surrounded by double ` characters. I am not sure if every class is well documented with the help() function so this could be error prone. This feels like a fragile solution but for the StaticmeshActor it seems to match the docs.
get class list of properties for unreal.StaticMeshActor
[USER=“2003”]Jamie Dale[/USER] you are kind of right, but actually even the example from the documentation does not work.
import unreal
obj = unreal.MediaPlayer()
with unreal.ScopedEditorTransaction("My Transaction Test") as trans:
obj.set_editor_property("play_on_open", True)
obj.set_editor_property("vertical_field_of_view", 60)
It does not create the history entry, even if it is calling only [FONT=Courier New]set_editor_property(). It only works if I insert [FONT=Courier New]obj.modify() before setting the properties and it looks painful if I have to do this for every change I want to do.