Loading object into level from save file, Array element is Null

Hi, I am trying to make a blueprint that will save a base’s “building elements” and then load them back up after loading the game. But for some reason when I load the save file, the elements of the array saved within it are null even though the length is right.

I am unsure where the problem is into my blueprint to be honest and this is why I come to you for some help.

Edit: Also to note, the saving part works fine. If I save and then load without restarting the game it works fine, but as soon as I stop and press play again it seems to flush the array. It will stop working as well when there is no object in the map that has the tag for some reason.

Here are the blueprint parts involved:

  • The Saving and Loading: [Link to BlueprintUE][1]

and

  • The Loading Function: [Link to BlueprintUE][2]

Edit2: Adding proper images to make it a little clearer.
Saving Pieces

Loading Pieces

Load Save Function

It’s quite hard to tell what’s going on, because that site changes a lot of stuff, but…

Let’s get the save game concept straight first:

  1. If there is no save game, then you can make one and save it to the slot. You never need to make a save game at any other time. I notice your are making them in both your save and load routines.

  2. Don’t use async save, especially not in a loop. The only time you need async save is if you have 1000s of actors or a lot of large data structures. In that case, it should only be called once. It doesn’t handle multiple calls well.

If you tell me a bit about your data, I can show you how to do this…

PS: That’s why it looks like your arrays are initializing, it’s because you’re constantly overwrite the save game with a new one…

I found one of the potential part I was overwriting and changed it:

From:

To:
(Buildings is the array I add the objects to before setting the save one with it and is probably useless in that spot since I clear it anyways when building. I’m probably going to remove it from that node-line altogether to make it simpler.)

I’m still going to look in case I’d find another place I overlooked like that.

Oh I understand now. Yeah I thought I had to create a new CreateSaveGame for the loading as well to save the newly loaded file into. I will try that change real quick.

For some reason it seems to still be overwriting. Should I remove the CreateSaveGame completely from the save part?

Saving Part:

Function:

I updated the main question with proper screenshots. Sorry about that ^^’ I didn’t know about the other site potentially changing things.

  1. Currently the “Load Save” function’s “does save game exist” does nothing since I’m forcing the save to be created in the save part, but I plan on changing it a little once it works to make it less “hard-coded”.

  2. Thanks for the explanation ^^, the last thing I tried said to use that so I did for the time being since I hadn’t much else to try, but I changed it back to the regular synced one.

Basically I am trying to save objects created when playing (like a building game, such as rust or space engineers.) and then load them back even after the game has been closed and opened back. Basically like a proper save file.

I am unsure where the overwriting is happening if you could maybe point the node in question that does that? ^^’ I will take a look real quick whilst waiting for an answer in the possibility that I would find where the overwriting is happening.

As for the object itself I am trying to save, here is the data I am trying to save.
(Basically I am trying to save the whole object into an array/list.)

And the savegame blueprint’s structure I use to save said objects into:

(BasePieces is of type BP_Base_Cube)

311101-capture4.png

Right, you still have the same problem :slight_smile:

The only time you need to use the node CreateSaveGame is -ONCE-. Never again. The only time you use that is when there’s no save game. Once there is a save game, you never have to call it again.

From then on, you only ever need to read it and write to it.

Here’s a hint, that will save you a lot of problems:

  • When you want to read, no problem, read the save game, cast it, and get the variables.

  • When you want to write - read the save game first, update it and write it back.

So you’re just ( at the moment ) saving transforms of cubes, right?

Oh, yeah I forgot to answer it on the other post. Yes only the cube transform ^^’

I accidentally had the wrong file name in the string inputs, but it didn’t seem to change much.

I’ll write one and show you ( just cube transforms ). Gimme 10…

Ok. So I made a cubeBP, all it has is a cube and an ID ( integer ).

Somewhere, like begin play ( and then never again ) you have this:

Saving the cube transforms:

Loading them again:

Notice how I never call create save game in either… :wink:

Works perfectly! I understand where I went wrong now ^^

Thanks a lot <3 Now the next thing I have to fix is my bad attempt at making the building part :stuck_out_tongue: But that’s for another question/thread ^^

Excellent :slight_smile: