Idea on how to implement a redo button in runtime for applied materials on actors?

Hi,
Any idea on how to implement an undo button in game to make an object return to its original state ?
Like you drag and drop a material by error on an object and you want it to go back to its non-modified state

You can store state data in an array of structures and call the last item in the array to undo.

Create a button widget and add an event dispatcher.
image

Create a structure where you will store data for undo
image

Create a structure where you will store data for undo.
Add an array variable of the structures to your blueprint.

Call the button widget and subscribe to the click.

I have described the most straightforward way. However, you can build a more complex undo-redo system. Look at this post: UE4-21 UNDO in realtime - #2 by Supremative

Also, I’ve built a complex history system in my Runtime Editor:

2 Likes

Thank you for the help!
What type of blueprint are you referring to ?

Any type, where you build your game logic.

1 Like

Is there any inputs in your event dispatcher ?
I have these errors:

Use Assign when working with delegates:

This way you (almost) never need to worry about signatures.

2 Likes

I must have missed a step, I did everything as indicated, the code is blocked after the branch (I know it thanks to the Print String) and nothing happens… do I have to put elements in the array? I may have missed the logic


Here is another example:

Introducing the Command Design Pattern in Unreal Engine 4 - YouTube

it’s same idea as shared above, but the commands are wrapped into objects. For undo some materials it is not likely needed, however if you wanted to watch some step-by-step I thought it may be worth a share.

1 Like

Execution blocks because you have an empty array. When assigning a material to a component, you must add the item to the array. You should set the material through the event ApplyMaterialWithUndo. It looks like you set material somewhere else.

1 Like