Where to put player stats?

Hey everyone,

I wonder where should I put actually some stat variables for the player like health, hunger, stamina, radiation etc? A pawn? A PlayerController? And then if I do say hunger variable, I want to make a “food” item which on Use to replenish the hunger. For example somwhere I have variable hunger = 300, then when the item is Used, add 50 to hunger. Should I extend from Actor->Item->Food?

What works best for me is storing variables where they would be logical, If i have a var for Hunger then i declare it on my pawn, , Same goes for Inventory,Thirst etc , I do keep stuff like XP Etc in my player controller tho

And to make a item that replenish your hunger the usual way ( if you are going to have tons of different behaving items ) then extend actor, create your base item class and then each individual item from it

Cool thanks for the reply. You mentioned XP, do you actually have a working XP system? I tried to make one myself but I don’t know how to actually give XP to the player. Well I know, after a kill was executed by the player, but I don’t know how to call the Kill function :frowning:

About the items:
So lets say I have 2 types of items food and drinks, I do the following:


For the items, very much yeah tho i would keep the functionality for both food & drinks in the same item class and just have a check for whatever it should be treathed as a drink or a food But thats just my personal choice

And for giving XP To a player all you need is the event where the Pawn or any pawn dies, get its instigator and if its a player (trough typecasting ) you can easly access it and do your XP Mechanic

Pretty much like this which is straight from ShooterGame

void AShooterGameMode::Killed(AController* Killer, AController* KilledPlayer, APawn* KilledPawn, const UDamageType* DamageType)
	YourController* PlayerPC= Cast<YourController>(Killer);
	if (PlayerPC) // If the Killer is a Player 



THANKS YOU VERY MUCH!!! I was looking for that method for like 3 weeks :smiley:

Back in UDK I remember it was ScoreKill, here it was renamed but I didn’t know how… THANKS A LOT! I will try to finish my xp system finally :slight_smile:

I did try it, but it seems that this method is not implemented in the engine… I mean there is no function that is called when a pawn is killed. I believe your code comes from the shooter game example?

In UDK you could indeed use ScoreKill for when a pawn was killed by the player i havent found the equivalent in UE4 so yeah you will have to implement your own i strongly suggest to check ShooterGame source to see their implementation of the killed event

Health and death aren’t concepts we kept in the engine for UE4 since they are so design-specific that they would need to written custom in most cases anyway. But yeah, ShooterGame is a fine example to work from.

Thanks, I will take a look :slight_smile: