Store destroyed actor in an Array?

Hello, I can not manage to store destroyed characters in an array to be respawn after.

Let me explain, I am creating a system where the player has several soldiers (generated by a BP master) but they are not all in the world. I would like that some are stored in the Main Controller and other (placed by the player) are in the world.

I first tried to store these actors in an Object_Array, but when the actor is destroyed, i can’t have an access to his variable. Then I tried doing an Array of the Class of my actor, but it seems that it only stores the variables by default.

How can I store a destroyed actor in an array or other storage to have access to his stats (generated randomly)?

If you need more info let me know. Regards, .

I don’t know why it happens but maybe Destroy tells the garbage collector to pick it up.

To work around it you can create a Struct that holds copies of all the actor’s variables, and store that in tge array instead. Then when you spawn a new actor back in you can access that struct from your array and copy the values back into that new actor.

i would say you shouldn’t bother destroying the actor in this case just set it to hidden while not in use. of course its very situation dependant, like if you have 100 actors then this may not be the best option. you could also create a array of structs, where the struct contains all the pertinent information about the solider like class, stats, name, etc. then you arent really storing the the solider just all his defining characteristics. this would make it somewhat easy to recreate it after its destroyed.

the reason that what you were trying didnt work is once a actor is destroyed its gone so any references to it become invalid and even if you spawn an actor of the same class its reference will be different.

Thanks for your answer Thompson and Mighty, I will probably make a Struct with all the variables, but there is not a cleaner way to do this?

Maybe there is, but if you want to retrieve information from an Actor and that Actor has been destroyed, the information is gone with it, so you’ll have to either store the information elsewhere the whole time, or copy it elsewhere, or not destroy the actor.

For example if I need information to persist when a Pawn is destroyed, I store that information in the pawn’s Controller class, because the controller will exist for the entire level.

If I need information to persist between levels, I store it in a Game Instance or a save file (which I load when the player’s PlayerState class gets created).

But if your Actors are not Player-related, then you’ll have to come up with your own place to store it in memory (that doesn’t get destroyed before you need to retrieve it) or save it to a file if it will get destroyed before you need to retrieve it.

Actors lose their information when the actor is destroyed.
Objects which are not actors are not placed in the level, so they do not lose information unless you delete the object.