Where should I store my Health Value!

Hey guys simple question!

Where should I store my character stats, like health, amount of lives and items collected.

The player can died and respawn, so holding them in the character is a bad idea, I was thinking the player controller is that correct? because if they die controller does not get deleted.

Thanks!

Hi,

You are free to store it anywhere you like, you always need to consider the game you are making. In your case, I would personally store it in the Player State. It is replicated, so it can function in multiplayer too, and it consists for the whole game, but keep in mind that loading a new level will reset the values in it.

Might as well look at this answer : Storing character stats - Character & Animation - Epic Developer Community Forums

It always depends on your needs.
In most cases, the Pawn is suitable.

If you are going to develop for multiplayer, you have to consider whether other people should know of your health.
The PlayerState is automatically created per player and is replicated between players.
The Controller is a bad idea if you want to have multiple pawns.
If you store the health in your controller and you want to change pawns. The Pawns will have a shared health then.

I for myself prefer PlayerState. and use the Mode to decide what happens in certain circumstances.
For example I have a Health and Air Value in my PlayerState.
The GameMode checks if my Pawn is underwater. If it is, the Air is reduced. If the Air reaches 0, the Health decreases,too.

Store them in the character it’s easier to manage, just don’t destroy that character when it dies. Just remove life or drop the items.

You’re the one that has to decide what happens to the character when health reaches 0, it doesn’t mean you have to destroy that character, just set its location somewhere.

Add a “death animation” create a delay… then spawn it after clicking (OK) in the town or something :slight_smile:
Destroying it means basicly you legit destroy it like mobs where you don’t want to use that mob anymore.