Announcement

Collapse
No announcement yet.

Save System

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Save System

    Hello fellow devs, I'm here once again to ask for your support

    I'm trying to develop a save system where i save player position, the player keys, the player coins, player rotation, coins in scene, keys in scene, enemies in scene and all the positions of the coins, keys and enemies.

    What i do is simply using the save system in unreal editor to save it to a gameslot and then load it form that same game slot. The problem is that it seems to save to the slot and load from the slot, but it doesn't actually "load". Here's what i mean:

    https://youtu.be/cBpapZsdLQ4

    Here is the log that says what is saved,

    Click image for larger version

Name:	saved.png
Views:	50
Size:	133.3 KB
ID:	1737261

    And this is the log that says what is loaded,

    Click image for larger version

Name:	loaded.png
Views:	47
Size:	96.4 KB
ID:	1737262

    (this logs are not from the same scene as the video, in this one there're just enemies)


    But as is seen in the video the coins doesn't appear on the HUD, the player doesn't stay in the same position as saved and the coins and keys aren't preserved.

    Why is this happening? I don't really find no answer to this question anywhere in the internet, maybe because it's quite an specific problem.

    Could the position be conditioned by the player start component? That could do for the position, but what about the many other things?
    Attached Files

    #2
    Originally posted by RunningLate3 View Post
    Hello fellow devs, I'm here once again to ask for your support

    I'm trying to develop a save system where i save player position, the player keys, the player coins, player rotation, coins in scene, keys in scene, enemies in scene and all the positions of the coins, keys and enemies.

    What i do is simply using the save system in unreal editor to save it to a gameslot and then load it form that same game slot. The problem is that it seems to save to the slot and load from the slot, but it doesn't actually "load". Here's what i mean:

    https://youtu.be/cBpapZsdLQ4

    Here is the log that says what is saved,

    Click image for larger version

Name:	saved.png
Views:	50
Size:	133.3 KB
ID:	1737261

    And this is the log that says what is loaded,

    Click image for larger version

Name:	loaded.png
Views:	47
Size:	96.4 KB
ID:	1737262

    (this logs are not from the same scene as the video, in this one there're just enemies)


    But as is seen in the video the coins doesn't appear on the HUD, the player doesn't stay in the same position as saved and the coins and keys aren't preserved.

    Why is this happening? I don't really find no answer to this question anywhere in the internet, maybe because it's quite an specific problem.

    Could the position be conditioned by the player start component? That could do for the position, but what about the many other things?
    You need to show your save and load code, that's where the error is...

    Comment


      #3
      Originally posted by ClockworkOcean View Post

      You need to show your save and load code, that's where the error is...
      Hey, thanks for answering!

      For saving the game i create my own SaveGame BP where i create this variables:

      Click image for larger version

Name:	1.png
Views:	51
Size:	13.9 KB
ID:	1737394

      For saving the game, I've created multiple funcions that store the information and then i save them to the slot. I've added an input to each function that is a reference to my SaveGame_BP.

      Here's what the main save and load functions look like:

      Click image for larger version

Name:	2.png
Views:	39
Size:	84.1 KB
ID:	1737395Click image for larger version

Name:	7.png
Views:	38
Size:	65.3 KB
ID:	1737396

      This is my function for saving coins and loading (i do the same with the keys):

      Click image for larger version

Name:	3.png
Views:	42
Size:	58.1 KB
ID:	1737399
      Click image for larger version

Name:	8.png
Views:	40
Size:	91.4 KB
ID:	1737398

      This is my function for saving the position of the coins (i do the same with the keys and the enemies):

      Click image for larger version

Name:	4.png
Views:	38
Size:	135.3 KB
ID:	1737403
      Click image for larger version

Name:	9.png
Views:	40
Size:	129.7 KB
ID:	1737401

      This is how I save and load the player position:

      Click image for larger version

Name:	5.png
Views:	37
Size:	66.8 KB
ID:	1737404
      Click image for larger version

Name:	10.png
Views:	39
Size:	108.1 KB
ID:	1737405

      And this is how I save and load the player rotation:

      Click image for larger version

Name:	6.png
Views:	38
Size:	66.3 KB
ID:	1737407
      Click image for larger version

Name:	11.png
Views:	37
Size:	100.9 KB
ID:	1737406

      I haven't added the function that i use for saving the level because they work just fine.


      I have the save function in my Character blueprint but I call it from the pause menu casting the player. That's because I've also created an autosave function, and i couldn't make it work form the pause menu nor cast the pause menu from the player to do it in the Character BP.

      I have and call the load function from the MainMenu BP, using an onClicked Event (when the playe hits the play button, if there's an existing game in a slot, it charges it):

      Click image for larger version

Name:	12.png
Views:	36
Size:	77.1 KB
ID:	1737409


      And that's pretty much my Save System. I hope I've explained everything well enough!
      Attached Files

      Comment


        #4
        Well, first thing right out of the gate I'm noticing, is that your save game function always creates a new save game. You only need to do that if there isn't one already there. You're basically overwriting the game every time.

        Is that any use, or shall I look further?

        Comment


          #5
          Originally posted by ClockworkOcean View Post
          Well, first thing right out of the gate I'm noticing, is that your save game function always creates a new save game. You only need to do that if there isn't one already there. You're basically overwriting the game every time.

          Is that any use, or shall I look further?
          Thanks for your response!

          I didin't noticed that, could it really affect the performance of the load system tho? It's my first time doing a save system with unreal and I'm kinda lost.

          Comment


            #6
            Originally posted by RunningLate3 View Post

            Thanks for your response!

            I didin't noticed that, could it really affect the performance of the load system tho? It's my first time doing a save system with unreal and I'm kinda lost.
            Well, it's not affecting the performance, but it's overwriting your game every time you save anything, that's why it's not working ( I think )...

            Try this:

            Click image for larger version  Name:	savegame.JPG Views:	0 Size:	73.9 KB ID:	1737514
            EDIT: ( again ). I don't think I was clear. Yes, obviously when you save you need to overwrite the savegame, but you're overwriting it with an empty one every time...
            Last edited by ClockworkOcean; 03-26-2020, 05:13 PM.

            Comment


              #7
              Originally posted by ClockworkOcean View Post

              Well, it's not affecting the performance, but it's overwriting your game every time you save anything, that's why it's not working ( I think )...

              Try this:

              Click image for larger version Name:	savegame.JPG Views:	0 Size:	73.9 KB ID:	1737514
              EDIT: ( again ). I don't think I was clear. Yes, obviously when you save you need to overwrite the savegame, but you're overwriting it with an empty one every time...
              Thanks for answering! Unfortunatelly, it still doesn'r work :/

              It saves everything and loads everything but the information that loads still doesn't "show" to the screen (player sitll don't move to the loaded player position nor rotaion, coins doesn't appear on the HUD counter, enemies still alive...)

              What else could it be?

              Comment


                #8
                Originally posted by RunningLate3 View Post

                Thanks for answering! Unfortunatelly, it still doesn'r work :/

                It saves everything and loads everything but the information that loads still doesn't "show" to the screen (player sitll don't move to the loaded player position nor rotaion, coins doesn't appear on the HUD counter, enemies still alive...)

                What else could it be?
                Ok, let's concentrate on just player position, can you show me the code for LoadPlayerPosition?

                Comment


                  #9
                  Originally posted by ClockworkOcean View Post

                  Ok, let's concentrate on just player position, can you show me the code for LoadPlayerPosition?
                  Sure! Here it is

                  Click image for larger version

Name:	10.png
Views:	23
Size:	108.1 KB
ID:	1737770

                  What I'm doing here is just casting to the player and setting its position to the position saved in my custom SaveGame BP (which is the input of the function)

                  Comment


                    #10
                    Originally posted by RunningLate3 View Post

                    Sure! Here it is

                    Click image for larger version

Name:	10.png
Views:	23
Size:	108.1 KB
ID:	1737770

                    What I'm doing here is just casting to the player and setting its position to the position saved in my custom SaveGame BP (which is the input of the function)
                    Right try the same thing, but set the location of the pawn, not the controller. Tell me what happens...

                    Comment


                      #11
                      Originally posted by ClockworkOcean View Post

                      Right try the same thing, but set the location of the pawn, not the controller. Tell me what happens...
                      It shows me a bucnh of "accessed none" errors:

                      Click image for larger version

Name:	13.png
Views:	21
Size:	254.6 KB
ID:	1737813

                      Comment


                        #12
                        Originally posted by RunningLate3 View Post

                        It shows me a bucnh of "accessed none" errors:

                        Click image for larger version

Name:	13.png
Views:	21
Size:	254.6 KB
ID:	1737813
                        You only need to change the bit that sets the player location. Instead of setting the controller ( because a controller doesn't really have a location ), you just need to set the location of the player pawn. So just change the bit of BP ( above here ) to set the player pawn. Nothing else should be affected.

                        Comment


                          #13
                          Originally posted by ClockworkOcean View Post

                          You only need to change the bit that sets the player location. Instead of setting the controller ( because a controller doesn't really have a location ), you just need to set the location of the player pawn. So just change the bit of BP ( above here ) to set the player pawn. Nothing else should be affected.
                          I can't get to make it work either, this is how i tried to implement it:

                          Click image for larger version

Name:	14.png
Views:	17
Size:	112.3 KB
ID:	1737827

                          Does this follow your idea or is it an absolutelly diferent concept?

                          Comment


                            #14
                            Originally posted by RunningLate3 View Post

                            I can't get to make it work either, this is how i tried to implement it:

                            Click image for larger version

Name:	14.png
Views:	17
Size:	112.3 KB
ID:	1737827

                            Does this follow your idea or is it an absolutelly diferent concept?
                            I've written an example for you. It just deals with player location, get one thing sorted first, then add the rest. It doesn't need to be on a timer, it could be in a menu or when the player hits a volume etc.

                            Part 1:

                            Click image for larger version

Name:	part1.JPG
Views:	19
Size:	168.5 KB
ID:	1737833
                            Part 2:
                            Click image for larger version

Name:	part2.JPG
Views:	16
Size:	106.2 KB
ID:	1737834
                            Also attached here. It's a text file, just open it in any text editor, copy all, go to your level BP and paste.
                            SavePlayerPosition.txt

                            Just make a new level and put this in the level BP. Every time you stop playing and start again, it will put the player back where they last left off.

                            Tell me how you do

                            Comment


                              #15
                              Originally posted by ClockworkOcean View Post

                              I've written an example for you. It just deals with player location, get one thing sorted first, then add the rest. It doesn't need to be on a timer, it could be in a menu or when the player hits a volume etc.

                              Part 1:

                              Click image for larger version

Name:	part1.JPG
Views:	19
Size:	168.5 KB
ID:	1737833
                              Part 2:
                              Click image for larger version

Name:	part2.JPG
Views:	16
Size:	106.2 KB
ID:	1737834
                              Also attached here. It's a text file, just open it in any text editor, copy all, go to your level BP and paste.
                              [ATTACH]n1737835[/ATTACH]

                              Just make a new level and put this in the level BP. Every time you stop playing and start again, it will put the player back where they last left off.

                              Tell me how you do
                              It still doesn't work but now it has a different error! Hahaha see, it loads a different position that the saved one. I know it for the logs, here are the logs:

                              Click image for larger version

Name:	15.png
Views:	20
Size:	23.6 KB
ID:	1737855

                              I implemented your approach to my particular case and now, when i start the game with the play button, i do this:

                              Click image for larger version

Name:	16.png
Views:	15
Size:	106.4 KB
ID:	1737856 -------------> Click image for larger version

Name:	17.png
Views:	15
Size:	37.5 KB
ID:	1737857 ---------------> Click image for larger version

Name:	18.png
Views:	15
Size:	93.9 KB
ID:	1737858

                              And when i save i still cast the player from the pause menu but the saveGame function looks like this now:

                              Click image for larger version

Name:	19.png
Views:	16
Size:	30.6 KB
ID:	1737859 ---------------> Click image for larger version

Name:	20.png
Views:	16
Size:	115.0 KB
ID:	1737860

                              Where could the problem be?

                              Comment

                              Working...
                              X