Some saved variables go back to default value

Hello! This is my first post so sorry if i do something wrong.

I’m saving some variables using SaveGameToSlot. The problem is that there’s a map which is saved and loaded flawlessly (ObjetosPorZona), but the other one (EnemigosPorZona) always loads its default values. I checked if its not saved correctly but it is, and i save and load the 2 maps the same way,so i dont understand where the problem is, can someone help me out? I’m working on UE4.22.3.

Here’s where i save all the variables.

As you can see, i use a struct inside the SaveGame to set all the data. In ObjetosYEnemigosPorZona I get the data to save in the 2 highlighted maps in the next picture.

Here’s the collapsed graph.
And here’s the end of the saving function, which always ends succesfully and the Slot Name never changes.

The loading function:


You don’t have to save everything all at once, you can have a macro that just saves a certain variable or structure etc.

This is my save game 101:


It’s hard to tell from what you have there, but the 2 main problems people have are:

  1. Making a new save every time ( which overwrites the last one ).

  2. Getting the save game reference into a variable and not using that variable in a consistent way.

If you always just load,update,save in one operation, everything gets much more simple.

1 Like

I think i’m doing it the same way you are, but my functions are longer.
So it’d be correct if i use my saving game function more than once? I’ll try that as soon as i can, thanks for your answer!
About the 2 main problems, i don’t think I do that cause:

  1. I only create a Save Game Object once
  2. I don’t think i’m not using the variable inconsistently even tho i’m not sure how to check that
  1. would be stuff like writing to the variable, but not using the save node later…

I made sure the SaveGameObject child variable is not inconsistent so i deleted it and used it exaclty the same way you did (getting it directly from the cast node), but the problem persists.
Could you also tell me the correct way to partially save a game? I’m not sure if I’m doing it well.

Thanks again.

That picture I gave deals with saving parts of the save game.

Load the save game, update only the bit you want and the write it back.

I tried it only saving the maps (which now are map filled with integers cause i had to get and older version of my project).
Maybe the structure where i save all the data is the problem here and i should get rid of it? I’ve had some headaches because of them in the past so maybe…?

https://forums.unrealengine.com/core/image/gif;base64
​​

So you have two arrays of ints, what are the blue things? Ah, other structures? So it’s a recursive structure?

I have 2 maps, both filled with integer keys and integer values (previously was byte keys and byte values). The blue things are other 3 structures which, expanded, are like this picture I posted before:

https://forums.unrealengine.com/core/image/gif;base64

It’s not a loop of structures cause they all are different type of structures. let me show you better, these 3 are the same, but splitted:

So here, I just made a save game which holds a recursive structure. You update it like this:

If you get it working with a simple setup, it will work with a more complex structure.

Still not working (i omitted the previous steps so you can see it better)

https://forums.unrealengine.com/core/image/gif;base64

I also noticed that both of the maps are not loading correctly now after being converted to integer maps.

You mean I should make it all into an only structure?

This looks fine. As long as you don’t have code elsewhere that’s wiping the save game, when you read it back in, the struct data should have been saved.

The struct can be as complicated as you like, but what I’m saying is, get it working for a really simple example first ( in a new project maybe ), then come back and fix this.

I tried this example and it seems to be working perfectly



Now how do I make it work in my project?

Just do the same thing, but with your current data structure.

Ok this is how im doing it in the new project:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_216801_1617016439559_343”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_216802_1617016451910_203”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_216803_1617016461654_939”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“data-tempid”:“temp_216804_1617016477073_200”}[/ATTACH]
https://forums.unrealengine.com/core/image/gif;base64

The data is saved and loaded correctly (all the values go from the default ones to mostly -20).
I did it pretty similar with my old project and seems to be working, but why? what am i doing wrong when i was saving and loading like i did originally? and what do i do now?

Your pictures didn’t show for some reason.

At least it is working now :slight_smile:

I have no idea what the difference is ( too much code here I’m afraid ), you’ll need to study the differences.

Oh sorry, can you see them now?


I still have to make it work with all the additional steps… But yeah at least it’s something. I guess I’ll be adding them progressively so i can see where it’s failing. Thanks for helping a noob out, I might add more posts in case i can’t find the problem.

Okay, I think its finally working. I realized there was something wrong with the way the maps where being loaded (still don’t know what the exact problem is) and i replaced the maps with arrays filled with a new Structure which contains 2 integers: ID and InitalQuantity. The saving and loading is practically the same, but using structures, here’s a picture on how I’m saving it and I hope this helps people with the same problem:

My conclusion is that I’m going to avoid using Maps as much as i can