Save and load levels?

I tried for some time and played around with the saving and loading stuff in ue4. I want to have the save object to save the current level the player it on, when they exit the game, they get into the menu and they press continue to go to the level they were at before. I dont think I need some enumeration thing or anything like that, I just use “Get current level name” node to receive data for the level. I need to load it, but thats where the problem actually is.

i think your just missing an "open level " node, right after you load the game.
plug in the level name in it and it should work

hm, ill do that. I also did something which is that I moved the loading code into my player blueprint “Base_BP” and when I do begin to play with a do once node, the load just keeps opening. So I may be getting somewhere. But tracking the variable and where the code is, is an important thing. I might be able to figure something out. But I’m still a little new to the saving stuff in ue4. Thanks!

Oh ok, also when I added the loading and saving to base_bp, this image shows what happening as it spams the strings in seconds, and it’s with the do once note.
Another thing happening, when I go into a level selector widget, I open a different level, then I transfers me to the default level value I set before.

yea, it’s just spamming the level of the default value I set for the current level variable

There definitely something with saving, maybe loading. but i think the saving is wronge, and its weird because the loading code loads ONLY the default value on my current level variable. If i leave it empty, i start PIE, it just closes without an error. It says failed to start PIE or something

Good idea, idk why I didnt think of that, haha. But unfortunately its still not working. Meaning when I start off in a level, then i exit to menu and click continue, it goes black screen. The Main Menu uses a complete empty level, so I think that my save is overwriting when I go to my Main Menu (which is an empty level that opens a widget). So I may need to redo this but i’m not sure what to do. I also use a seperate gamemode for the Main Menu, creating the save is based on my player blueprint (“Base_BP”).

you should track the current level variable it might just be wrong at some time.
you can display it in a widget or print it on screen

be aware that when using name as references, sometimes the engine adds a _C to the name while referencing the package or the asset

you really don t want to do this :slight_smile: because in ue, the pawns and player controllers are not persistent, that means they reset each time you open a level. i think you should put your code in the game instance class (wich is persistant) or the laoding level function can be in your widget too so you can handle when it triggers

plug your Current level variable in the print string (in String).
and place that print node where you load or save the varaible so you know what you save

if it doesn t change, that means it s not set or save properly

oh ! and you should use a does slots exist node, overwise it will overwrite it each time with the default value.

Ok, so now the Saving print string has stopped, so that’s good. Now the level is just constantly opening. If I fix that problem, then we can move on to figuring out why/how to load from the level that was last played on, and exclude the main menu level from it

Oh, alright thanks!

to simplify, you should not use the open level for now, just figure out why it s not saved/load using keyboard input for exemple , and then , once your save/load is good, put there the open level

I was able figure it out, thanks @expose!

So basically, my save game object has a “Level” string variable, then in my player bp, I added another string variable called “CurrentLevel” then the screen shots shows the code to add to solve this issue.