How to save actor's random location?

Hello! How can I save an actor’s location after I have spawned it into a random location. I have tried everything that I can but it just doesn’t work. I can only make it to spawn into a specific location after saving but not into a random location.

You can always spawn at a random location.

Where you save the location depends on how long you want to keep it:

  1. Not very long, the character can record it’s location on begin play

  2. Between levels, you can put it in the game instance

  3. Between game plays, then use the save game.

Yes, I’m trying to save between game plays. How do I save the random values of the location to the game slot. I have tried several things but they don’t work.

Here’s my savegame 101:

Thank you! Here’s what I tried but it doesn’t work. This is my latest attempt.

That looks ok apart from you didn’t create it?

You do have to create it, BUT ONLY ONCE. I type that in capitals, because for some reason, everyone has a problem with that…

I experimented a lot with different things, here is the latest attempt. It doesn’t print the string at the end when I spawn the actor and try to save the location so something must be wrong with it.

That would work if you had connected up the branch node:

336228-screenshot-10.jpg

:smiley: OH NO, I was too hasty! I connected it but it still doesn’t print the string. :frowning:

There is one more thing to consider here I don’t see mentioned above. Once you get the save game working following ClockworkOcean’s 101, you will notice the saved position is still incorrect.

This is due to the way nodes are evaluated; simplified, your setup looks like this:

This will place the actor in one location and Print a completely different location. It will not print the location of the actor. Every time a white wire is executed on the node, the pure nodes in the back will get reevaluated. In short, the random node triggers twice and generates 2 different results.

What you really want is either this:

  • here the variable is stored first and we use the same variable to Spawn & Print

Or this:

  • here, we pull the data from the actor:

But that’s something to consider after you get the Save Game thing going.

Well, I guess I will pile on to this conversation…

Unrealistic Engineer, in your latest setup the blueprint is doing these steps:

  1. Spawn your Actor at a random location
  2. Make new Game Save if there is not one already
  3. Save the location in the Game Save

The problem is, you never actually read the saved location. Right now, you are just generating a random location, and then saving it, and then when you restart your game, it generates another random location, and saves that.

I think you need to change it to these steps:

  1. Check if the Game Save exists
  2. If it does exist, get the random location and spawn there; and if not, create a new game save object and generate a new random location, spawn there, and save it.

Hope this helps

I see, so here’s what I tried recently. The problem is that it doesn’t save it, it just prints false. I tried several other things but it just doesn’t save it for some reason.

Oh, YES! That was it, I forgot the name in the Default Save Game Slot, I just assumed that the error was somewhere else! It works now perfectly! Thank you very much, problem solved! :smiley:

I think the only way you can have this continuing problem is that the variable with the save game name in is empty…