No announcement yet.

Save Game not working

  • Filter
  • Time
  • Show
Clear All
new posts

    Save Game not working

    Could someone pls help me figure out why my game dosent save.
    The print string is firing. But when i close and reopen my game
    the variables havent been saved.

    The image is pretty bad. Better to zoom in on the "save game" and "load game" portions. That is where the issue is not all the variables you are saving or loading. BUT from what I can see it looks like when you "save" game you aren't actually "saving" anything. You are telling it to "load" a game. So the first time you play there would be no game to load, of course it will print the string but that just means the custom event was called. As for the event init in your game instance, you would have no saved file the first time it is run, so it creates a save game object. which you then immediately "save" to a slot without changing any variables. So it saves a "default" value of all your variables in your SaveGame object. You then proceed to "load" this blank SaveGame and set all your variables from that. So nothing ever gets saved. The wiring is all messed up on this. I would do this:

    1. On event init in the game instance check and see if there is a saved game, if so, you can cast to it and get all your variables and set the game instance version of those variables from the SaveGame data.
    2. When you want to "save" data, have a function that you call, create a save game object, take all the current game instance variables and "set" the Save game variables in the save game object you just created, then "Save Game To Slot". This will now save the "save game object data" to whatever slot you desire.
    3. Next time the game is started, it will see a save game object, pull that out, cast to it and set all the game instance variables from the save game variables stored on the save game object.


      Hi, Thank you for the reply. Ive zoomed in and created better pictures.
      Here is the zoomed in game instance. On event init wich as i unerstand it runs as soon as the game is created, i make
      sure there is a save slot, if not i create one.Im using the same file name and index as the game only needs one save slot.
      So one is only created the first time the game is started. Ive checked that the file is there and it is. And there is only one file
      'so i dont think the problem is that the game is reading from the wrong slot.

      The SaveGame event is called when exiting the widget where the player customizes their avatar. It looks like this:

      This is where the variables are loaded in from game instance to the PlayerCharacter pawn (Its a pawn as it will not be moved around in the level)
      I have checked the loading process by printing out some variable values from the save fileto make sure the problem isnt in loading them. But they
      are reset nothing has been saved.

      The chagnes the player makes to the character are remain until the game is turned off.
      I think i am doing what you are recommending doing on point 1 and 2. Im a beginner at UE th,
      this is the first time im working with save game. Am doing what you are describing or have
      i missed something?


        The problem is you are creating a "save game object" when you start if one doesn't exist but that is not how the save game object works. You kind of have the wiring backwards that is why nothing is saving. Think of it like this.

        1. You play the game collect points or whatever and store this variable in your "game instance".
        2. You play 5 levels get up to 1,000 points and the game instance remembers this value between levels.
        3. You exit the game and start again, the game instance is reset each "instance" of your game that you play. So you start back at 0 pts.

        Now, you want to "save" this data to an external source so that when you play again you pick up at level 5 with 1,000 points not level 1, 0 points. So what are you going to tell the computer to do to accomplish this? It needs instructions? Right now, your instructions basically say:

        1. Start game
        2. Check if we have a save game (which you never will the first time)
        3. No...create a save game
        4. Save the data in the save game object we just created to a "slot" (at this point you haven't even played the game yet and you already saved data out to a "slot") The data saved here is the default values our case 0 pts, level 1
        5. Next you told the computer to set all the game instance variables to this default value of the save game object in slot 0, at this point you haven't even started playing the game yet
        6. Now you start playing, collect 500 points and are on level 3, you decide to "save" and quit the game, so you tell the computer to "save" the data right? Wrong!
        7. When you save, what the computer is actually doing now is pulling the data you saved in the "Save Game to Slot", which we already know has only default values in it because you created the save game object and saved it to the slot when you turned the game on because we had no save game data at that point.
        8. Next you pulled out the default values and set something with them...and I'm assuming saved it to slot again (can't see in the screen shots), so in essence you are just pushing default data around and around.
        9. Next time you load the game, it will see a saved game data slot BUT as we have shown, this will STILL hold the default data so it appears like nothing happened, which basically is true.

        So how do we fix this?

        Don't create a save game object if one doesn't exist on start up. If one does exist you can load it and pull the data and set your game instance data from the save game data.
        When you finish playing and want to save, that is when you create a save game object, then pull the variables from the save game object and set them to the same variables contained in the game instance. Once you have set all the save game object variables to the values in the game instance this is when you "Save Game to Slot". Now you have actually changed the save game object data and saved it out.
        Next time you start the game it will see a save game slot, you then "load game from slot", this will pull the modified save game object out, now you use that to pull the variables you previously set, and now you go in reverse setting game instance variables to save game object values. I hope this makes sense. I have included screen shots of how I do this for clarity.
        Attached Files


          I got it working now after reading your reply.
          I really appreciate you taking the time to explain this to me. I was totally stuck!
          Thank you so much!!!


            Cool! Glad it's working now.


              I made a tutorial for this in case anyone else stumbles upon this thread and learns better with a walk through.