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 :smiley:
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?

Here is my Event Graph in Gamemode blueprint

And here is Event Graph in Players blueprint

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

I also have HUD that displays that amount.

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.

2 Likes

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?

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?

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

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).

1 Like

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

Hi @FL1PPY19 I am doing a school project and encountering the same problem, I can’t figure out by following all the helps above, could you please share your finished blueprint, thank you very much!