Save the location of weapons on map

Hello guys,

Since few weeks, I have been working on a save/load system for my 2 player coop game. So far, it’s working perfectly for my characters (their locations, ammos, health and so on).

However, I’m having a hard time with items that can be picked up. What I do is the following :

  • A weapon is placed on the map (a child class of Blueprint Master_Pickup)
  • In runtime, I save the game before picking up the weapon.
  • I pick up the weapon (so the weapon is attached to my FPS character and the one on the floor is destroyed)
  • I load the game a first time
  • The weapon that I picked up spawn correctly at the location it was before and my character loses his weapon (so far so good !)
  • The problem is that when I reload once more, the weapon does not appear (it does spawn since I make a print string on the return value of my “Spawn Actor from Class” and I get the correct name (with a different number after the name)

I think I’m doing something wrong. Here is how I did it in the Blueprint.

=> First I do a “Save game on slot” (working fine for my character blueprints) in which I store all the weapons present on the map in an array (“ItemClassArray”), as well as their location in “ItemClassTransform” array.

This array is created in the Gamemode Blueprint (the server) as you can see on Screenshot 1

=> When I load the game (screenshot 2), I get the Item Array and Transform Array from the Save slot and in the Gamemode Blueprint, what I do is that I check whether the Actor is valid. If it does exist, I just don’t spawn the weapon and apply a setactortransform so it just go back to the loaded location. If it is not valid (meaning I picked up the weapon and it has been destroyed on the floor), I spawn the class at the previous location.

The problem is that it works when I load the save once but not twice or more in a row. I don’t get why I have a return value on my “Spawn actor of class” but I cannot see the weapon on the map.

Do you guys have an idea where is the problem and if there is a better way to code this ?

I’m thanking you in advance for your help !

Sanglier Man

My bad, in my message, Screenshot 1 is actually Screenshot 2 (you have to look at the second one first)

I don’t get your logic entirely, but I don’t work in this area much, so that could just be me. But I can tell you one thing, your item is spawning, just not where you think it should be. Try printing the spawn location also :slight_smile:

Hello ClockWorkOcean,

Thank you for the reply. Basically, the logic is that I’m saving all the weapon class in an Actor Array and their locations in a Location Array. Then I save both arrays in my save file. When I load the game, I call the save file which can tell where the weapons have to spawn on my map based on their previous locations.

On the first screenshot I’ve posted, you can see that once I spawn the weapons with the For Each Loop, I’m saving the game again (right after loading it) so that the save file knows that some weapons have been respawned on the map (the weapons that I have picked up after saving the game once).

I will check your idea by printing the spawn location and see, I’ll let you know :wink:

sanglier man

Hello guys !

I managed to correct what I was doing. ClockWorkOcean was right, when I loaded the game once more, my weapon was spawn below my terrain. This was due to an operation I was doing when saving (I was adding -50 to the Z location of the weapon in the save file).

I was a mistake on my side. I can now save and load my weapons correctly.

Thank you !

Sanglier Man