x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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! :) Greetings, Stefan

Product Version: UE 4.22
Tags:
more ▼

asked Apr 23 '19 at 06:58 PM in C++ Programming

avatar image

Steferich
111 4 7 12

avatar image Lardo Deepdelver Apr 24 '19 at 03:25 PM

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.

avatar image Steferich Apr 25 '19 at 04:07 PM

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.

avatar image Lardo Deepdelver Apr 25 '19 at 07:27 PM

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 https://answers.unrealengine.com/questions/42349/how-do-i-use-the-savegame-flag.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 25 '19 at 08:55 PM

avatar image

phil_me_up
1.5k 6 6 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question