UE4 imagine sims or any type of builder game that lets you place objects and UNDO if you don’t actually need them or UNDO any last movement or change you made in realtime using Widget.
You could implement this with a stack of action objects.
-
You should create an Action class where you need to add three events: Execute, Undo and Redo.
-
Next, for any action you want to process, create a class inherited from the base Action class and add the necessary data there.
-
Override events: Execute, Undo and Redo in child class.
-
Create an array(stack) of Actions objects in another class where you want.
-
At runtime, add a child class object to the array for each action.
-
Next, you can move up and down the stack by triggering Undo and Redo events
In the same way, I implemented the history of actions in my runtime editor:
If you want to spawn and destroy actors, it is better to store data about the actor instead of directly referencing it.
I create a GUID/Actor map for all actors in history and store only GUID and data about the actor. If the actor was deleted and restored using Undo-Redo, the whole history would remain valid.
Does BP_ActionTransform have no errors? Would you show EventGraph?
It’s still not working
Download this example(UE5), please:
History.7z (556.8 KB)
Do you have any idea on why it is not working because, I tried the same way as yours. I am still not able to figure out the problem.
Have you downloaded the example on the link above?
Yes, I did and tried the same way as yours but not working
What exactly doesn’t work for you?
Okay and then if I have to assign the undo to a widget and apply it to a static mesh in actor BP class
Create a button widget and add an event dispatcher.
In your controlling blueprint, create the widget and subscribe to its dispatcher event:
Thank you so much for your help!
Is it possible to apply the undo for static mesh actor instead of object, will this work?