What do you mean be an action like something like in Prince of Persia or more basic?
Hey all i’m currently searching for a way to accomplish in game action history to make a undo and redo buttons, any ideas of how to accomplish this with ue4?
I’m trying to create a RTS like game with a level editor for it.
And the level editor should have undo actions, like with ue4 when you press ctrl+z you undo your action.
More like deleting an object and have a back button so it would appear or simply returning it to it’s last non modified state. As if pressing ctrl+z
What i’m trying to make is a RTS like game with a level editor for it.
Users, that’s why asked about runtime, imagine sims or any type of builder game that lets you place objects and redo if you don’t actually need them.
What world logic are you making, RTS FPS mouse and click? Because as now I think you trying to make a Word document in an unreal engine.
Alright, you trying to make level editor in runtime? Because its a lot easier just to use the engine level editor and go around its limitation than create a new one from zero, or you want the user to create levels as well?
Alright that actually quite simple all that you need to do is have a parent actor for all of your objects that way if it will be really easy to work with, then you just add a “parent objects” array somewhere and when you add an object to the world you add its reference into the array. It will always add it at top of the array, now when you press the undo button just delete the object and give back the resources. Well, this is the simple example of what you want the next comment will be the more complete one, for movement and redo as well.
Again it’s easy but long I start if you want to do it like this just send a comment and I continue if not it’s alright.
1.This is for creation: Add an enum with “create, destroy, move” then create a struct in it have the enum then “parent object class” and a “location”, now you need to change the array to array of structs that you created and now when to build an object you make a struct get the “reference” and do “create” for the enum then add it to the array. And when you press the undo button you first do a switch for the enum here for “create” make a function because you will use it, let’s say with the name “Kill” in it you take the object reference and make it hidden and disable its collision then add it to a new array of object references with the name of “destroyLater” and you take the top struct of the array of “Undo” and add it to array “Redo” when you press Redo button make a switch and for “create” do the opposite to what you did in undo.
DDemons comment would be the simplest way to do this.
If you want to take a deeper look at this, the Command pattern is how this is usually done in Software Development.
You basically have a base class (or even interface) “Command” that has an Execute() and Undo() and Redo() and whatnot. Then in your child classes (usually referenced as “concrete command”) you implement them. Childs would then be “SpawnActorCommand”, “DeleteActorCommand”, etc. Every command the user executes comes into an array so you can keep them for undoing later.
If you think this is overkill, just go with DDemons approach ;D