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"

Player State VS Player Character

If i have a bunch of data that varies from character to character (Health, mana, energy, levels, etc). Would it make sense to put all this in Player State or Player Character?

Product Version: UE 4.7
more ▼

asked May 20 '15 at 10:14 PM in Blueprint Scripting

avatar image

91 30 30 32

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

2 answers: sort voted first

PlayerState is used to replace PlayerController in network replication for all clients so it is exist through out the level with PlayerController and it use use to store the variable that matter even if your character is not there or dying like score, level, kills, deaths, character type/class,...

Anything that define of your character you can put in like health, mana, energy....

For example in MOBA game, your should put level in Playerstate, coz when your character die, all the stat in character will be reset, so you still can grab the level from Playerstate and re-init your character base on level, same go with items, weapons. In case of disconnected and reconnected, PlayerState will be saved, and your can get back all of that when player reconnect to server.

more ▼

answered May 21 '15 at 02:55 AM

avatar image

Duncan Dam
3.1k 121 50 164

avatar image Allenheathx Jan 26 '18 at 09:37 PM

Why use Playerstate instead of Game Instance though? Say you are loading character costume on event begin play of character from the costume being stored on Game Instance. As far as I can tell all clients can see the costume loaded correctly so would you still need the Playerstate acting as a bridge between Game Instance and Player Character in this situation or is it redundant?


avatar image Duncan Dam Jan 27 '18 at 12:18 AM

Hi, this explaination is for Multiplayer Game where you need PlayerState to handle player data between server and all client. Game Instance is unique for each server and client, and it's not replicated so if you doing Singleplayer game you don't even need PlayerState.

avatar image M.FatihSaglam Jul 07 '18 at 09:01 PM

Hi Duncan. Do you mean, I can store last player stats (like 'gun-ammo, exp, inventory etc.') in server's local save folder automaticly -via blueprints, without c++? And if player rejoins after 1 week, will player init with last stats?

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

PlayerState is extension of PlayerController, main diffrence is that PlayerState is replicated, PlayerController is not. PlayerController is not replicated for security reasons, if PlayerControllers information would be contained in client memory there risk it could be manipulated, it a open window for cheat software, best example is GTA:SA multiplayer mod which fully synchronizes clients without any safety measures (since GTA:SA is not really made for multiplayer), typical single player hacks are normally replicated to other clients there. Thats why PlayerControllers are only on server side and they control pawns on server which later are replicated to clients. PlayerState is where you place information from PlayerController that you want to be replicated to all clients, but server should not relay on that information, so you just copy information that clients need to know.

Same thing with GameMode and GameState

more ▼

answered May 21 '15 at 03:14 AM

avatar image

37.1k 935 172 1116

avatar image Kiruse Jan 25 '17 at 05:49 PM

Part of this is blatantly wrong. "PlayerControllers are only on server side" is incorrect. Granted I do not know how this played off in May 2015, but the PlayerController is replicated ONLY for the player that owns it. Meaning the client has only a single PlayerController instance on their machine - namely their own controller - while the server replicates the various controllers to the respective clients. This is extremely important for client-server communication as it allows processing of input through RPC events easily without even having to worry who the events are replicated to.

"PlayerState is extension of PlayerController" is also wrong. PlayerState is its own class hierarchy and the first parent class the two share is AActor. PlayerState is, as Duncan Dam pointed out, designed to store data across sessions. It is a form of container, not a form of controller.

When it comes to security, the server should always sanitize player input. In your MOBA example, the server simply shouldn't accept the request to trigger a spell twice within 0.5 seconds when the cooldown is supposed to be 3 seconds. Of course the fact PlayerControllers aren't replicated across all clients helps greatly and might be one reason for this implementation. But it certainly is not enough to protect your game.

(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