Can't save when closing game

I am having some issues with saving my “map”.
Been following Ali Elzoheiry’s guide on Saving Game ( https://www.youtube.com/watch?v=H6rqJbwjRIk&t=1747s ) and it’s great.
When I play the game and progress the “map” it saves just fine. I am entering combat and re-opening that same level with the map and it’s how I left it. My problem is, when I am restarting the game, it keeps creating a new map every time. I feel like I am very close to it saving to the game slot every time it’s created, but I am either misunderstanding how the SaveGame works or I have no idea what the issue is. One thing I know for sure and tested with printing it, is that the variable MapSaveS has a value right after the UI is created and added to the viewport, but that value is gone when I close the game even though I THINK I am saving it.
Any help is appreciated!




What is “BP Gameplay Map” class ? Is it an object ? If so, you have two objects here, the BP_SaveGame and the BP_GameplayMap. When saving to slot, you should only have one master object with primitive properties, avoid sub-objects or references.

In this scenario, when saving BP_SaveGame, it saves a reference to the existing BP_GameplayMap object instance, but it doesn’t save anything from that object. When loading after a restart, it tries to resolve the object reference which does not exist.

You have several options :

(1) Move variables from BP_GameplayMap directly into the SaveGame object. Or save BP_GameplayMap instead of SaveGame.

(2) Turn BP_GameplayMap into a struct. Structs can be saved within an object.

(3) Use a different slot for each object. For example “Save1” for the master object, “Save1_Map” for the map sub-object, etc.. Each object/subobject will require a SaveGameToSlot/LoadGameFromSlot call. I wouldn’t recommend this though as it is prone to desync/corruption.

(4) With access to C++, you can do the equivalent to SaveGameToSlot but temporarily keep the result in memory (as an array of bytes). This means you can gather save data for multiple objects and save them all into a single savegame.

I am slightly more confused now.
BP_GameplayMap is my User Widget blueprint that has all the logic and variables for what appears on screen ( such as buttons, lines and what not )
BP_SaveGame is my blueprint of type “SaveGame” class. What I understood from the tutorial is that I am using this class, as place to store as variables all my other blueprints that I want saved.
By how confused I am now, I am not even sure I even know what I am talking about. I assumed that if it “saves” when switching levels ( without closing the game ), it would be a matter of I am saving it poorly to the slot ( which probably still is ), but really I have no clue where to start fixing it from.

What you said with save “BP_GameplayMap instead of SaveGame” sonunds like the next step forward, but not sure how I would go about it

Okay so this is correct, but you misunderstood one major component : you cannot save other objects.

What you need to do is, save all the variables necessary to rebuild from scratch the state you want. By variables I mean primitive ones, such as strings, floats, integers, and also arrays and structs of primitive variables.

In your case you need to figure out a way to save the state of your map, which seems to be randomly generated, and then player can progress through it. I can see two approaches :

(1) Change your random map generation a bit to use Random With Seed everywhere. When generating a new map, start by generating a Seed, then generate the random map using that seed. Then, you can store the Seed of the map in SaveGame, and when loading, use that Seed to regenerate the map. Afterwards, you need to save which nodes have been visited by player (progression). You can do so with an array of booleans, or something like that. Looks like a bunch of rows, so probably an array of array of booleans. If you need to save more information than just the visited state, make a struct representing the state of a node.

(2) Alternatively (but similarly), don’t touch your random generation, and save everything you need to regenerate the graph, including positions and types (which were randomly generated). Start by making a struct representing the state of a node, including its X,Y position, room type, and visited state (and other things if necessary). Make a “Row” struct which is just an array of nodes. Then in SaveGame store everything into an array of Rows. After loading you should have everything you need to recreate the graph.

The first approach should be easier as you can re-use your existing generation code to rebuild most of it.

Ok, now it makes so much more sense what I was doing wrong and to be fair, should’ve been pretty obvious.

I’ll give first approach a shot, as I wanted anyway from the start to use “Seeds” for my maps, I was just hoping I can avoid it just to make it easier for me.

Thank you so so much