How to load saved character data when moving to another level

Hello colleagues, I need your help in solving a seemingly simple but obscure issue. I’m having trouble loading my saves when changing levels …
I have a structure in which I save my character’s variables (health, equipment, level …), I store it in SaveGame, in GameInstance I created two functions responsible for saving and loading character variables. There are two levels in my game. Level 1 (main menu) and level 2 (game level). These levels have different game modes. When I test saves at level 2 (game level), they work fine, so I concluded that there is no bug in them. The problem occurs when I want to load saves from level 1 (main menu). Every time I load my saves I get the start of a new game.
I tried:

  • initialize the character, then cut it out because I didn’t get the desired effect and got a lot of errors. In the process, I came to the conclusion that it is not very necessary since I have a single-player game;
  • I tried to study level streaming, but all the examples that I found were done within the boundaries of one level (the level was simply divided into separate zones);
  • Tried to figure out the teleport function, but couldn’t get it to work;
    At the moment my level loading looks like this

    Please help, I’m sure the problem can be solved easily, but due to lack of experience I’m at a dead end.

we’d need to see more code to have a guess at this one, but for now just test if your Refs are valid

Hello @Auran131, could you please indicate which parts of the code you want to look at?

Now, when I try to load a saved game from the main menu, I get errors (for all variables in the structure), if I load at the game level, then there are no such errors.

The errors refer to “ContinueGame” which is located in the Game instance (here I load the slot and set the values ​​of the character variables from the saved structure)

This is how I create a slot in a Game instance

This is how I save a slot in a Game instance

so its telling you something is invalid, but it works in levels.

based on what i can see you’re using GetPlayerCharacter but does the character even exist in a main menu?

No, it doesn’t exist in the main menu, since the main menu and the game level have different game mods

that’ll be the problem then,

if you only have one player character you can just store its savedatastructure directly in the gameinstance, then on the character begin play you can check if that save data exists and load directly from the gameinstance

I was just thinking about this and will try it out right now. I also managed to find information that you cannot change the game mode during execution from the blueprints (not 100% sure, but several threads on the forum indicate this).

Found the solution here I have trouble with load game button in main menu - #5 by ThompsonN13
In short, it’s about loading your saves in a game mod. I did this by using a boolean variable, when I start the game I set it to true, if I continue the game I set it to false. In my game mod, when starting, I check the value of a variable and select the desired branch.

Start a new game from the main menu

Continue last saved game from main menu

Game loading function

Game mode on my game level

@Auran131, thanks for your help and for giving me the right idea.

just be careful with load orders,

if your character doesn’t exist when the GameMode begin play fires it will fail.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.