Saving all objects state in a level


I’m trying to made an old-school FPS. The levels are very similar to a Quake1- like progression : you have to reach the end of level by killing ennemies, but you can move freely in the level (so you can come back where you started if you want) ; you have also to collect objects (powerups, keys, …). So, when you have to save the game, you have to know which enemy is dead or not and which key(s)/ powerup(s) has /have been collected.
That is my problem : when I load the game, I want my level exactly the same as I left it for the last time (so if I picked up a key, killed monsters, or taken power-ups, it must be memorized). I already read the documentation for saving game with blueprint, watch several videos on YouTube, but found nothing I was looking for. Is anyone can help me?

Someone might have a better suggestion but as far as my knowledge stretches I’d create a saveGame object and save all the data in there (monsters would be an array of types and another array of their transforms etc). It sounds like you’ve already familiarized yourself with these things probably but that’s how I’d do it. You’d then have to obviously create functionality that runs through the sameGame object and places the actors once a game has been loaded.

Hope that helps somewhat.

The problem is the level loading. The actual level you play is saved in the save game object, and you have to load it and open it with “Open Level” node. However, if you do that, the level will be opened with all ennemies with their original locations, not the locations they were after you left the game. That’s why I need to save “all the objects state in the level” ; you see?

Add interface to each object you want save. For eg. to pawns “Enemy interface” for pickups “pickup interface”
Use those interface functions (you created them anyway) to get their locations and rotations, hp etc.
To get all actors: use “get all actors with interface” this creates array. Use that array with foreach in array loop.

You can also create EventDispatcher called “time for save”. Make all pawns and pickups register there.
When you trigger that event each pawn and pickup should add its own info to array.

For storing that data in array it is best to use structs. Each element of array may be then structure that has “location” “rotation” “HP” “type of object” etc.

I don’t see how it changes everything. Anyway, I don’t think you need Interface for that. Simply use “Get All Actor from classes” and it’s done. But again, as I say, when I load my level using “Open Level” node, my objects and ennemies will be back at their start location… :-/

Interface is more fancy way of get all actors from classes, you can add interface to all actors classes you want save.
How many different classes in fps game you can have that you want to save state? I think around 10 is quite accurate estimation.
So with interface you do it all in one loop. With Actor from class you need 10 loops, 10 arrays.

And use Structs for save/load else you end with 50-60 arrays for 10 different classes.

For open level problem:
Do not place actors statically from editor in level. Instead make blueprint class that is simple arrow, mesh or icon with some enum that tells what type of spawn point it is.
This way when level loads you will have only spawn points, not actual monster/pickups. Then either you populate them from save data or from some array that holds default state.

This post is old but for those who would wonder, the solution I use is to set a global variable “IsLoadingSave” to true just before loading the map, and in a blueprint you have on every maps, execute your game loading routine (replacing objects, characters, whatever…) on begin play IF the global variable IsLoadingSave is true, then set it back to false. That way, nothing happens if you’re loading the map “normally”, but you trigger your loading routine AFTER THE MAP LOAD if you indeed wanted to load a game.