Announcement

Collapse
No announcement yet.

How to keep score after respawning an character?

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

    How to keep score after respawning an character?

    Hi everyone! I'm writing here more often then I should but this is my only hope
    Today I've implemented respawn system. As you can guess it uses Actor destroying in certain situation and then spawn new character in particular place. It works pretty well but I found out the score that player got earlier resets and items that gives score are still picked up and aren't on the map anymore.
    So I want to keep the score after player's dead. Is there any possible way to transfer this score from destroyed actor to a brend new?

    Click image for larger version

Name:	respawn-in-game-mode.JPG
Views:	2
Size:	151.0 KB
ID:	1666370 Here is my Event Graph in Gamemode blueprint

    Click image for larger version

Name:	respawn-in-game-mode.JPG
Views:	2
Size:	151.0 KB
ID:	1666371 And here is Event Graph in Players blueprint


    I have variable that keeps information about amount of points gained.


    Click image for larger version

Name:	coins-amount.JPG
Views:	1
Size:	102.9 KB
ID:	1666372 I also have HUD that displays that amount.

    #2
    Hi FL1PPY19, you can create a custom Player State blueprint and set the score inside it. So even if the player character dies, your score variable will remain intact and there's no need to add any additional logic to handle it. Plus you can access it from your HUD class (get Player Controller >> get Player State >> Cast >> Get Score).

    Also, make sure to set this new Player State as the default Player State class in your Game Mode.
    Blog | Youtube
    NEW:
    Tower Defense Starter Kit (v2.10) | Wave Spawning System [50% OFF FLASH SALE!!] | Top Down Stealth Toolkit [v4.23]

    Comment


      #3
      Ok, Thank you but how should I do it properly? I should create variable with score inside the Player state and delete variable in Character blueprint?

      Comment


        #4
        So I did something like that. I cast my coin that gives score to Player State instead of to Player. And i deleted variable in Player and created variable in Player State. Is that ok?
        Click image for larger version  Name:	this.JPG Views:	3 Size:	122.8 KB ID:	1666723

        After that, how can I do it to display it on my HUD?

        Click image for larger version  Name:	Przechwytywanie.JPG Views:	1 Size:	114.7 KB ID:	1666725
        Last edited by FL1PPY19; 09-19-2019, 02:50 PM.

        Comment


          #5
          Yes since you have the variable in the Player State now, you won't need it in the Player Character.

          Now inside the "Get Text 1", delete the cast to Player Character and use the following node setup: Get Player Controller >> Get Player State >> Cast to your Player State class and Get the Coins Amount variable.

          In the overlap, you can cast the "Other Actor" to your Player Character (since your character is the one overlapping and not player state), and then use the same set of nodes I mentioned above, but with an additional step to Set the Coins Amount (which you've already added).
          Blog | Youtube
          NEW:
          Tower Defense Starter Kit (v2.10) | Wave Spawning System [50% OFF FLASH SALE!!] | Top Down Stealth Toolkit [v4.23]

          Comment


            #6
            Thank you very much! It worked Thanks for sharing your time and experience to help me. I really appreciate this

            Comment

            Working...
            X