Download

Undo Destroy Actor or Reset Level

I have a level where I use a Trace to hit actors and Destroy them. This is done to hide objects that are clicked. Is there a way to be able to undo Destroy Actor? Say click it to hide it, and press another button to unhide it?

Or is there a way to just reset the level, but keep my character in the current location? Currently, I am using a button to trigger Execute Console Comman “Restart Level”, but that also resets my character to the starting position.

You could save the hidden object as a variable, or add it to an array, and then reference that when you want to un-hide it again.

So I could add all objects that can be hidden to an array, then un-hide that array with a command? I looked into arrays yesterday but couldn’t seem to grasp the concept too well. If I have 5 static meshes that I want to create an array with, how and where do I do that, so I can call that array in another function?

Well, lets say you want to have the money af a person in a game, then we might store that as an integer variable. So let’s say we have Peter. His money would be designated by the variable “PeterMoney”.
But if he has a whole family, and we keep their money seperate, we would hvae to create a seperate variable “JaneMoney” and “MarcusMoney”.

So to save ourselvel sometine we could instead make an array of integers. An array is just a collection of certain variables. Each separate entry in an array is called an index. (And the first one is 0, not 1 just to confuse). So instad of creating sperate variables, we just make an array called “Money”.

So if we say that Peter from now on is 0, Jane is 1, and Marcus is 2. Now if i wanted Jane’s money, i would just get the array “Money”, and get index nr. 2.

Where it saves us time, is that maybe we have a Happiness and an Energy variable on each of them (and their 500 neighbors), and now i if want all info about Marcus, i can just get the relevant arrays and get index nr. 2 in each of them, instead of keeping a seperate for every person in the game.

To your solution. You would create an array, and add the object you just hid, into that array. When you then want to un-hide it, you get that array and run a “For Each Loop” which is a function that does the same to each entry of an array, and make that function unhide them all.

You would call the array just like you call a normal variable.

Awesome. That helps a lot. I was able to create an array from several objects in my scene. I was able to call those objects like you said “ForEachLoop.” I set it up so far to DestroyActor on that array. That works fine. What node/command can I run to either reset that array, or unhide/undestroy those actors? I can’t seem to find one that works. Here is my event graph as it stands right now.

Add, Get & Clear are going to become good friends of yours.

To reset the array, you can use “Clear”. This doesn’t do anything to the actors themselves, it just “clears” all the variables these actors are referenced by.
See it as a shortcut to the item, where deleting the shortcut, doesn’t do anything to the item itself.
However when you run a “destroy” function on it, you destroy the item itself.
Therefore when you destroy an actor, you can’t “undestroy” it. So when destroyed, that is the final action for that item. Instead you might want to use the “set hidden” function on it instead, if you want to keep the actors for later use.

Nice! That’s what I needed. Changing it from Destroy to Set Hidden was exactly what I needed. I had to also attach a set actor enable collision to each node as well so my character wouldn’t hit the objects when they were turned to invisible. But that did the trick. Thanks!

You’re welcome. Glad you managed to figure it out :slight_smile: