Download

Save character position in different maps.

Hi.

How could I do that if I went to another level in my project and save the game there, then when I restart my project, my character should be where I saved the game.
Currently, the save feature works, but it puts it back in the wrong map, not where I saved it.

I hope I have described my problem well, sorry if it is a little complicated. :confused:

Thank you for your help! :slight_smile:

When you save the game, make sure you’re saving the Level/Map you are in and Player Position.
When loading the game, load the map you were last on according to the save and then spawn your player in at the position you saved.

It sounds like you might just be loading a default map every time your game starts.

Thank you. :slight_smile:
And where can I set it to save both the map and the player’s position? :slight_smile:

You put it in the save game. It’s up to you what you put in there, so you can just store the name of the map, and the position.

EXAMPLE:

You get 3 Maps…
“Woods”, “Mountains”, “Desert”

Each has a unique Index
0, 1, 2

So, in your SaveGame Object, add an Integer <MapIndex>

Next, create a new Variable in your Savegame Object, a TRANSFORM. and called it <PlayerTransform>

Spawn the Savegame Object, and fill the two variables by saying: Player is in the Mountains, set Index to 1 and store the PlayerController.Transform into the Variables.
Now hit SaveGameToSlot…

For loading…
Best is to create a new Variable in a custom GameInstance, a TRANSFORM again. Call it <PlayerTransform_Holder>.
Create a second Variable (bool) als call it <GameIsLoading> and set it to TRUE.
When doing LoadGameFromSlot, store the PlayerTransform into that GameInstance Variable (GetGameInstance → Cast to Custom Instance → Set PlayerTransform_Holder)

From the Loaded Slot, readout which Index the MapIndex has, use a SwitchOnInt Node for that, and LoadLevel the correct Map.
Now, open the Level BP of your Maps and in BeginPlay, get the bool GameIsLoading from GameInstance (GetGameInstance → Cast to Custom Instance → Get GameIsLoading) and Pin it to a Branch.
When Branch is TRUE:
Get the Transform Holder from the GameInstance (GetGameInstance → Cast to Custom Instance → Get PlayerTransform_Holder).
Now Update the PlayerController Transform, to the GameInstance one…
Set the GameisLoading bool to false.
Finally, lead the last Executer to the stuff, that gets calle dwhen the Branch is false…

When Branch is FALSE:
Do whatever you need to do… spawning Enemies, Collectibles, do Game mechanic Stuff…etc…etc…

Done…

Ps.:
You can save the Level Name into the Savegame, which prevents from renaming issues… You can get the Level Name with GetCurrentLevelName.
So, after loading, simply do a LoadLevel with the stored name, instead of Index/Switch.

And for question, why saving the Transform into GameInstance:
The GameInstance ist persistent. Values stored into it, persist upon loading level.

Thank you everyone! :slight_smile: