Announcement

Collapse
No announcement yet.

Respawning/Restart Game Mechanic

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

    Respawning/Restart Game Mechanic

    Hello,

    I am new to UE4, and I am trying to make a simple endless runner game. I have basic mechanics like save game/score, best score, etc.

    However, I'm having trouble with the respawn mechanic. When the player hits a wall and dies, I want them to be able to press space bar, and have the game reset to the beginning, but keep their best score in tact. Can someone tell me how to do this? Been stuck for a few days, and I can't figure out how. This is what I would think should work, but it's not. Not sure what I'm doing wrong?

    Click image for larger version

Name:	Screenshot 2017-08-04 23.24.15.png
Views:	1
Size:	318.9 KB
ID:	1226308

    #2
    Originally posted by Norourke71 View Post
    Hello,

    I am new to UE4, and I am trying to make a simple endless runner game. I have basic mechanics like save game/score, best score, etc.

    However, I'm having trouble with the respawn mechanic. When the player hits a wall and dies, I want them to be able to press space bar, and have the game reset to the beginning, but keep their best score in tact. Can someone tell me how to do this? Been stuck for a few days, and I can't figure out how. This is what I would think should work, but it's not. Not sure what I'm doing wrong?

    [ATTACH=CONFIG]150915[/ATTACH]
    Try to save your variables in gamemode or game instance instead of putting your variables in character BP since once the character destroy all the variables will get reset .

    Comment


      #3
      Hello I'm new to UE4 too and creating a similar thing. Today I watched few tutorials on how to save stuff to save my coin number inside my game. Not sure if this will work for you but I'm sure you can learn something from it. Here are the two tutorials I followed and combined in a way to get them to work for me.

      https://www.youtube.com/watch?v=rbEESQUWgfM by CodeViper

      https://www.youtube.com/watch?v=LpMGm8pNN9E by Virtus Learning Hub / Creative Tutorials

      So far I don't have any reset button it will keep loading the last coin count on begin play and when I hit my save key (F3) it will save my current coin count. However I believe it could be easily set up to update on item pickup or every now and then via simple function.

      Here is my set up (it's a mix of the two tutorials so don't worry about my naming concept, as I said I'm new )

      1. Start by creating a new blueprint and chooses Save Game as type. Name it whatever you want in my case it's SaveGameTutorial.
      Click image for larger version

Name:	1.png
Views:	1
Size:	93.5 KB
ID:	1132117

      2. Open newly created blueprint and add new variables. This will be the things you want to save, for me it's SilverCoins and GoldCoins. Compile and save then close this blueprint. You won't need it anymore but whatever name you assisned keep it in mind, you'll need it later.

      Click image for larger version

Name:	2.png
Views:	1
Size:	4.1 KB
ID:	1132118

      3. Go inside your character blueprint and add new variable as show on the screen. You can skip this point and create this below when you create Save Game Object that how I created that variable.

      Click image for larger version

Name:	3.png
Views:	1
Size:	36.4 KB
ID:	1132119

      4. Now create 3 functions, SaveGame, LoadGame and UpdateWidget
      - Inside your newly created SaveGame function select SaveGame node and add two inputs. Here you create your save game object, assign the name of the blueprint we first created to store all the information, for me it's SaveGameTutorial. Rest should be clear if not you can learn from the videos or ask a question.

      Click image for larger version

Name:	4.png
Views:	1
Size:	111.3 KB
ID:	1132120

      - In your LoadGame function select your return node and add two outputs just like in SaveGame function. This will check if your save exist (make sure it matches the slot name of your save game) if it does it will load everything and if not it will set every value to 0.

      Click image for larger version

Name:	5.png
Views:	1
Size:	116.1 KB
ID:	1132121

      - UpdateWidget is simple just add two inputs: SilverCoins and GoldCoins, then grab your variables (SilverCoins and GoldCoins) from the left hand side and set them to whatever comes out the update widget.

      Click image for larger version

Name:	6.png
Views:	1
Size:	45.9 KB
ID:	1132122

      5. Change to EventGraph inside your character blueprint and Input Event for F3 key, get your save game function and plug it into pressed event, plug variables that need to be saved.

      Click image for larger version

Name:	7.png
Views:	1
Size:	54.5 KB
ID:	1132123

      6. Add on event begin play and plug your load function followed by your update function.

      Click image for larger version

Name:	8.png
Views:	1
Size:	62.0 KB
ID:	1132124

      So now when I play my game and hit F3 key it will save my Silver and Gold coin count and load these values next time I respawn/start the game. I know this is not a perfect solution and it might not work for you but it's a start and I strongly suggest you watch the tutorials above. Good luck with your projects! Regards!

      Comment

      Working...
      X