Setting Location of Multiple Actor Blueprints from Saved Vector Array?

I have a Actor_BP that allows me to set a mesh and pickup/ drop an object but I want to save the location of multiple objects without having to have a new blueprint for each object I want to move. I currently have a save system that works when there’s only instance of the BP in the level. I’ve set my Vector Variables to Vector Arrays but I cant’ figure out how to set each Instance of the object’s world location Independently. At the moment I load the save and all objects Spawn at the 1 saved vector and get launched into the air. I’ve look at documentation but I still cant piece it together.

The screenshots show my Save/Load Custom Events in the Pickup Objects Actor_BP

Yup, it’s because when you save the location, you make a one index array and overwrite the array you have in your savegame.

When you need instead of that code, is:

and you need to put it in an actor OUTSIDE the object. The objects can’t save themselves ( well, they can, but it’s much easier to do it externally ).

So put this code in a standalone actor in the level, or in the level BP.

Then, when you went to restore, you read the array from the savegame and:

Like that…

This is very helpful and explains a lot. I’ll have a go at implementing this.

Tell me how it goes :slight_smile:

In your example, where are you setting the location of the item for the array? At first I kept it in my ‘Pickup Items BP’ where it sets a Vector Array in my Game Instance which then set and saves another Vector Array in my save game. I then added the spawn actor portion to my level BP but It doesn’t seem to be setting any locations. I’m pretty that I’m just not setting the actor location in the right spot. Maybe I’m misunderstanding but I tried to set to actor location and add it to the array from my Level BP but I’m not sure how I’m suppose to get a reference to the Pickup Item BP in the level to get the location. I also created a empty actor in my level but I run into the same issue getting a reference to the items.

My apologies If I’m just being stupid…

Let me check. You want to save the location of multiple pickup item blueprints?

Yes, I have 1 BP that duplicated throughout the level.

Right, do this in the level BP. ( I don’t know exactly what your slot name and actor names etc are, but you’ll get the idea ). First of all you need an easy way to get a reference to the save game:

A custom event which saves the position of the pickup items:

And an event to re-spawn them later:

That’s it.

EDIT: Just corrected the code for the save. The old code worked, but had a bit of a slip in it.

Put everything in how it is in the images but I’m getting this error in the message log.

I think you might have made a slip, can you show the code?..

OK so the save reference:

The saving location :

And Loading the Items:

Ok, the code looks fine, I can only assume it’s something to do with those binds you have going on.

Try using keyboard strokes to trigger the save and load like this:

Remember to set ‘auto receive input’ to player 0 in the class defaults details.

I’m getting the same errors using the keys
Edit: I put some print strings at the end of both custom events. My loading event doesn’t pass the for each loop

And the variable ‘save game’ is of type ‘BP_savegame’ and your BP_savegame has a vector array in it called ‘Pickup item location SG’?

And you’ve compiled it?

Yeah, everything seems to be in working order. I added another print string to the save reference and its failed to cast to BP_SaveGame.

No idea I’m afraid. All I know is, it works fine here.

I can only suggest making sure absolutely nothing else is running and doing stuff to the save game.

When you get it working you need to a CLEAR on the save to the array, otherwise it gradually builds up a massive list of all the places the actors ever were :wink:

Ok I will add the clear to the save array. I’ll keep working on it, Thanks for the help.

Yes, sorry. It’s acting as if the variable isn’t declared.

Your comment about there being nothing else running the save game gave me an idea. I have the save set on my game instance for my characters variables so I put the save portion into the game instance and it works If I load the game without restart the level with the exception that the previous Item stay in the world. but when I load the level it forgets the location and just resets to the default location.

Game instance isn’t persistent between loads, that’s what it’s for. So stuff you put in the game instance will not exist after you exit the game a reload.

I had another idea. Just make a new level, nothing going on except the grey platform. Put the code I gave you in the level BP.

Only trigger it with the keyboard.

PS: This is what happens when you don’t clear the array :wink:

298885-clear.gif

( Started as 3 cubes… )

Also, if you fresh level idea doesn’t work, you can try a new project, that will DEFFO.