Reloading a map and serializing actors

Hi,

I’m reading through serialization, saving and loading, etc, and while I get the idea for the most part one thing I don’t quite get is the proper way to handle the following scenario:

  1. You had some actors placed via editor on the map.
  2. You start the game and some of those actors move, and then you also destroy some of the actors
  3. You save the game.

Now - on the next load, when you call openlevel, it will load the map and all the actors and positions that were originally placed in the editor. So at this time what is the proper way of reconciling changes between your save data and what’s originally stored in the map by level editor. I assume for actors that changed their position or state, etc, you can simply get that from the archive and serialize over the ones that were automatically loaded by the map, using name matching or something like that. But what about those that were destroyed ? Do you just destroy them immediately after the map loads ? Or is there a better way (maybe an event somewhere in load cycle of the map like ShouldLoadActor - so it never gets loaded from the original map data ? )

My guess is that you just destroy them immediately after the map loads.
Or, maybe you simply don’t put any actors in the map, all of them are spawned;
You would provide a default actor list, then if you are opening a new game, you spawn the actors using the default list; and if you are opening a saved game, you spawn the actors using the saved list.

This question have been asked a few times in my auto-save plugin thread;
The easier solution they used for it was having a ‘destroyed’ boolean (tagged SaveGame) value and set it to true then hiding the actor, not destroying it.
Then save the game… Now you can destroy the actor that should be destroyed.

On level reload, anything any actor that loaded the boolean ‘destroyed’ = true is set immediately hidden, then after loading is complete they are destroyed from level right after game start.

Using spawn logic and keeping a list would be a bit harder.

I understand this approach, but how to handle newly spawned actor?
The original actors can be destroyed or moved around, but what about new actors? They must be spawned again and placed in correct location.

Also I’d like to know how to properly save the level?
For example how do you save the ‘destroyed’ flag for all actors?
Did you save the whole actor including the ‘destroyed’ flag?

Thanks.

Actors have unique names in level;
Before loading the game from your .sav file, you spawn (again) the actors that are not in the level by default.
And yes, the ‘destroyed’ bool value is saved into the SaveGame within the blueprint actor information; if that flag is set to true then the actor that you create at runtime should not be there (and you destroy it again before removing the loading screen).

Another way of doing the same thing:
You can keep an array of actor (unique) names that you create in runtime, and the ones that you don’t want to respawn again in runtime, remove the name from that list in the SaveGame.
Then as always you make a “foreach name in array Spawn actor of class”… but with this approach you will have lots of problems with Actor unique name IDs.

yes, I save everything marked with the ‘SaveGame’ flag;
I’ve built a plugin (Auto-Save Plugin) to do this for me because it was a kinda hard process to track for so many actors in our game.