How can I create a Save Function?

Hello, i am back again with a serious question.
I spent the last 10 days with Youtube Tutorials and i never found a video, explaining how I can create a Save Game function, so that I can create an interaction with an object, that the player can use it as a “checkpoint”.
My problem is, that my save function saves my current level by name, but the player position is not getting saved. No matter how often I check every single step in my functions…
This drives me crazy.

1 Like

If you want to save the level and location, your savegame will need at least a string variable, and a vector.

When you come to the checkpoint, put the level name and player location in the save game, and write it out.

When you want to reload, you have to open the save game to see which level to open. Open that level, and THEN read the save game again, to position the player correctly.

If I’m in level A, I can’t have any code for positioning the player in level B, that has to run in level B. Does it make sense?

1 Like

Here i will show you my BP Classes @ClockworkOcean
This will be called, as soon as I click the Load Game button:

This is the Game Load function:

And this is the Load Game function:

And this is how the Save is created:

I am working since 5 months with the Unreal Engine, so please don`t blame if i am not seeing something obvious here :smiley:

It’s exactly what I said :slight_smile:

Everything after ‘open level’, ie all this

is not run. Open level basically put an axe through the whole thing, and then you’re in the next level.

You can’t put the player in the right place from here. You have to do it IN the level you’re opening…

1 Like

In short, do the bit where you read the player location and position them, on begin play in the new level.

1 Like

Thanks for your reply @ClockworkOcean !
Sorry for asking again, but the red marked square is not working as I built it. Okay. I understand.
I have to do that marked thing before “Open Level by Name” ?
Or where, or how should I set the player location?

Thanks again for helping me!

The stuff in the red square should go on ‘begin play’ in the level you’re opening :metal:

So in the level blueprint, an event on begin play. Which sets the playertransform, if there is one? Event BeginPLay - Branch - is there a save for this level? - true → playertransform - false → nothing. just start the level?

Presumably, you know where you want to put the player, if you do this

because ‘load game’ positions the player, right?

If you don’t know where you want to put the player, then you don’t need the code at all.

If you do know where you want to put the player, in the new level, then you have to read the save game ( to get the save ref ), and do the ‘set actor transform’ AFTER you’ve opened the level :slight_smile:

Yes :slight_smile:

1 Like

Okay got it!
Is there a possibility to talk to you?
Because I want to fully understand what happens there and why.
The thing I do not understand is, that in my Eventgraph, I am loading the level.And after that i get the playertransform. That confuses me.

Again: I just startet developing. And I am a little ashamed that I do not understand it right.

1 Like

I think we’re nearly there.

The main point to get is this. When you say

image

EVERYTHING is thrown away. All the code you were running, all the ideas you had going on etc. Because it was all in the old level.

A call to ‘open level’ totally wipes the slate clean. You have to start again, in your new level. The one you’re opening. Totally fresh. When you’re in levelA, and you open levelB, levelA get trashed, there is no levelA anymore. Just levelB…

So, the only way to sneak information into the new level is

  1. Through the game instance

or

  1. Via the save game

Because both of them survive this switchover.

You see, you said:

BZZ! There is no ‘after that’. Open level clears everything, including any code you had hanging on the end there…

Is it making sense?.. :smiley:

1 Like

Yes, this makes sense!
But I am still unsure how to fix this technically.
I tried it with this:

But I think you will guess… it did not work :smiley:

Does your menu disappear when you click the button?

The Menu disappear, and the right level is loaded. But as a new level.
I tried to save in a blank level. And after i saved it, and loaded, I went into the blank level. So the Level by name function is working fine.

But something is wrong with my transform thing.

Yes, because your menu is also getting thrown away when you call open level :slight_smile:

In the level BP of your new level, get a game instance ref and call ‘load game’

I already searched for a debug mode, where I can see what is inside the transform variable. But i did not find one