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.
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?
Here i will show you my BP Classes @ClockworkOcean
This will be called, as soon as I click the Load Game button:
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
It’s exactly what I said
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…
In short, do the bit where you read the player location and position them, on begin play in the new level.
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
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
Yes
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.
I think we’re nearly there.
The main point to get is this. When you say
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
- Through the game instance
or
- 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?..
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
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
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