How should I use my PlayerState compared to Character/Components?

Hey,

I’m making an RPG where I need stuff like health, stamina, mana and levels, experience, faction, etc.
So I was wondering, in which class should I store the various variables? In a PlayerState or Character/ActorComponent?

Currently I’m having health, stamina, etc. in the character and levels, experience, etc. in the playerstate. But I’m not sure if this is the best way to go. Do you have certain rules for what types of stuff goes where? What about inventories and skillpoints(points spent in various skills)?

Hope this was understandable, and thanks in advance! :slight_smile:
Greetings, Stefan

I personally would put anything that is connected to the character on the character.
Like health, stamina …

Anything that only the player has but should be able to communicate with other players (multiplayer) on the PlayerState (which is also just an actor so you can just make components for that as well so that you don’t overload on class)
Stuff like Level, XP (but that only counts if your other npc can’t level, otherwise they obviously should be on the character as well)

Things that are only for one player, his private data I would put on the player controller since that is not shared over multiplayer.
e.g. The inventory should maybe not be shared.

Okay, thanks for the reply!

I see why I’d have health, stamina, inventory, etc. on my character, but when it comes to savegames, wouldn’t it have to be stored in the PlayerState as well? I’ve heard you can make savegames directly off of playerstates.

Really depends on what you want to save,
we ended up saving quite a view actors additional to player data.

This link might help for that

When deciding how to implement these things I usually ask myself “Is this something that I’ll want to use across multiple character / object types”. If the answer is yes (and more often than not it is), then I’ll make it a component.

However, if it’s something that very fundamental or lightweight, I might put it in some base class which I’ll then inherit from (e.g. AEnemy, which I then use to create AEnemyMonster, AEnemyTurret etc).

To me, one of the big benefits of components is I find they help keep your code maintainable and potentally portable to other projects.