Download

UE4 - How to restore spawned actors at runtime with savegame?

Hi, i wonder, how to “save game”, spawned actors at runtime?

Runtime spawned actors have 2 issues, if they are destroyed, they canot be regenerated, but you can still make them hidden, the other issue, is, since they do not belong to the scene, you canot restore them by remember locations, etc, so i wonder, how to save them? I´m working on a project wich is open world, each spawned actor, has certain characteristics that player defines, like color, size, but obviously these actors dessapear when reloading the scene, because they where created in-game, and they canot be already in the scene,

I need to be able to save them where i left them and what they where doing and all them parameters, but how?

Please help

In the save game you just put the necessary variables to store this information. It could be an array of structs, for instance. Each struct would have:

Spawned location
Color
Size
Blah blah blah

When the player causes an actor to spawn, you put that info in the savegame. Later, when you re-run the level, at begin play your system opens the level and runs though the array you saved, spawning the objects and setting their qualities.

If I were to do this, I would make all spawned actors of a parent class, then before I leave the level, get all actors of that class and store their vector location and any of their other values in a structure, and make an array of that structure.then when the map is loaded, I would do a For Each loop on that array and spawn them.