How to save objects between maps?

Hello, I have a problem:
I can save any item as I need until the item is unloaded. I get references broken, when I try to add a new object to the existing save file, where I already have items from another part of the map that were previously unloaded.
I save interactable items (a chest, for example) with values like: the reference to the object, destroyed?, how many things were taken, whether it was spawned, etc.
I save and load information using the structures in which I have: a reference to the object and the object variables that I need to be saved. What do you do in this situation? How to keep the references to the unloaded items saved?

Are you saving in the game instance?

Hello, no, in the actor component

Well there’s your problem probably :slight_smile:

If you want to save information about the state of the game etc, you can do it in the game instance.

It looks just like a regular BP ( variable yada yada yada ), except it carries on existing between levels.

Works like this:

Thank you for the answer. I know what the game instance is, but why do you think it will help?
Even if I save all objects on the map in the game instance, it will break the existing references of the objects on the other map (just tryied that).
For example: If I save the reference of the object_a on the map_a (the reference I need to load variables in this object later) and then save the object_b and object_c on the map_b I will no longer have the reference to the object_a - in the new save file I will have reference to the object_b and c, and the broken (null) reference to the object_a

If these objects ( a, b, c ) are BPs that are written to always load and save their data to and from the game instance, it wont matter which map they are in. Even if it’s a different instance of object_a, when it begins, it loads it’s status and variables etc from the game instance and carries on.

If you’re talking about BP references ( ie, object_a has a variable of type object_b ), and when you change maps these pointers are lost, you can do one of two things:

  1. Write object_a and b so that they cope with this. So when object_a wakes up it looks for object_b and connects to it. Same for object_b

  2. Or, you could put them in the persistent level and have the levels the ‘appear’ to load in as just other streaming levels.

No, I don’t need save reference in the variable a to the variable b. I just need to save the reference of the object a to load its information
I have tried to save and load the information in the game instance, but the result is the same.
May be I do something wrong?
First of all, I collect the information about every object. Then I save collected information and load it again. The references from the first map are broken.

I just took a quick look, but will get back later with more info ( have to do a few things ). I do notice you’re using a save game, rather than game instance, which we’ve been talking about :slight_smile: ( although that shouldn’t matter much ).

The save game is what it naturally sounds like, whereas the game instance lives between levels until the end of play.

Thank you so much for helping me :slight_smile: I thought you want me to use the game instance to save the information
The fact is that I want to save information of every object, even unloaded or from another map — exit the game — enter the game again and load the information about objects.
Now if I save the object on first map, I will have the broken(null) reference to the object on the other map. If I save the broken reference - I cannot load the information about this object when I enter the game again.

Ok, so looking at it now, I’d say your problem is you’re loading the old save game, and appending it with all the stuff from the current game, and then re-saving ALL that. Then next time you run, you’re loading N lots of save game, where N is the total number of times you played!

Why are you appending? All you need is:

  1. Load all objects when you start
  2. When you save, overwrite the save game ( don’t append )

Am I missing something!? ( possibly… )

I need to append because if I create a save file for the first time on the map_a and then save again on the map_b I will save only map_b objects, objects from map_a will be unloaded (can’t get them from GetAllActorsOfClass). Thats why I cannot rewrite existing save file, I need to add unique object to existing objects and rewrite existing objects if they are on the current map. If the object is from the other map - I will not change it.
Append is a bad solution, I am goind to go through the save and add only unique objects (dont want to dublicate them)

I will definitely remove the append, this os not hard :slight_smile:
But what do I need to do with the references? I can’t solve this problem for a while
I don’t really want to use the streaming level with every object. How will I hide them when I am on the other streaming level…

Ok, but it’s defintely a big part of your problem I think. It would be good to only have copy of each object, and of course, you can’t store the references to objects, because they’re different every time you run a level.

Hold your horses, let me look at it a bit more, I think the basic concept of what you’re doing is absolutely fine.

Ok, back again already :slight_smile:

Am I correct in thinking that the save game slot name is the same as the level name?

So you have a slot for each level?

Then the append IS a problem. You only need to make one save game for each level, right?

If I’m playing level 1 and the cube is at X=250, you can save that in the slot. Then, next time I play the game, we see it’s level 1, load that slot, move the cube to X=250. But when I’ve finished playing, the cube is at X=500, we only need to save that. We don’t need the X=250 stuff anymore, it no longer applies. That’s the append problem. With the append, you’re putting more and more in the same slot: X=250, X=500, X=…

Do you see?

( excuse me if I’m wrong, had a long day… )

Wow, you are really cool, I have never thought about that :slight_smile:
I don’t use the level name based save slot name and I can’t see any issues in this solution right now
I can make the slot name from the level name and save the items for each level…
And I don’t even need to use append, each level will have his own array…
The player experience, inventory save system can be one-slotted, this is not an issue too.
You are a genius, I will try this solution as soon as possible

Ha! :slight_smile: Great.