PlayerState vs PlayerController MMOrpg

hello!

So Im doing a smal mmorpg. What is the main difference between playerController and playerState?
I ask because before I keep going, I have a feeling something’s wrong.

Example .- if i run 2 clients on a dedicated server [option clicked]
the only way the clients can “access” the keyboard input is if I make a custom event and tell the server this, then multicast it… after that my player can run… otherwise it wont because it doesnt get the input

Also I stored all my variables [health, mp, stamina, minDamage, maxDamage, etc] on my playerController… I actually never used playerState.

short story long: i basically need to send a custom event to the server and then multicast it (almost always) so every player can get updated (for example, the health, mana, etc)

What would you recommend?

Regards

Hi,

I did a project almost similar to yours not a long time ago. I can share how I approached it:

-I handled the Inputs in the Player Controller, when a key was pressed, I sent a message through a Blueprint Interface to my Character Blueprint (eg. a function named ‘Request Move Forward’ with an Axis Value float input).
-In the Character Blueprint, when I recieved a message from the Player Controller (eg. ‘Request Move Forward’) I executed a ‘Run On Server’ custom event called ‘Tell Server to Move Forward’. This custom event then executed a ‘Multicast’ custom event called ‘Multicast Forward Movement’. Finally this custom event called a function ‘Move Forward’ where I actually implemented the movement.

Regarding the health, stamina etc. variables I think the best place for those is the Player State. Player State was actually added later, providing an extra layer of managment. You are not forced in any way to use it. It is automatically replicated, persistent throught your whole game, but keep in mind that loading a new level resets it.

Hope I could help a bit.

Oh I see.

Basically on this MMORPG, currently my PlayerController has every single stat of the player (meaning I have not added a single thing to PlayerState…)… that being said, the only things that will get updated to the character are the health/mana/etc (on level up), when the player gets hit (their new health), the movements of the player… there are other stats (like hunger, strength, vitality) that will not replicate, that will be only for the player to know, so based on these stats, other stats can show (example: health = vitality * 2… or maybe damage = str * weaponDmg / 2…)

  1. Do you think this can cause network lag because of all the data being sent ? (especially the movements, I have the movements like you said)

On the other hand
2. You’re saying that if I leave the stats as it is (in playerController) there wont be any issues? I will have no more than 5 maps… a start zone, a big map with 2 cities, and maybe few more maps (like a shop, so players can be in ‘safe’)

Finally!
3. How would you go saving the character info (on the server side?) and then readding it to the player when they log in? I’m quite lost here and could need just some guidance :stuck_out_tongue:

Regards and thank you Kontur!

  1. I have to admit I am not a networking expert, especially if we are talking about a lot of players. I would say it mostly depends on the server. Are you planning to use a dedicated one? (well, you should for an MMO :P). Unfortunately I cannot provide you with information about the footprint each replicated variable leaves, but I think using a reasonable amount of them shouldn’t cause problems (the ones you mentioned are totally reasonable). You said, you want to handle some stat only on client side. Be careful with this, you shouldn’t let the client manipulate any gameplay related data, but if it is only for showing some stuff, should be fine.

  2. Yes, it should be perfectly fine in the Player Controller as well, using the Player State for this is really just a choice of taste. The only thing I can think of that you should consider is if you want to link the stats to a playable character or to the player itself. If to the player, Player Controller will work.

  3. For saving the stats, I would use an MySQL database that stores your registered players, their score, and the ID of each item the player had when logged out, and then I would query the database upon login and readd the stuff. Of course, you would have to setup your own ‘ID assigning’ system to give a unique one for each item/weapon etc.

I know that for implementing a dedicated server you need to recompile the engine, you can’t do it with the Epic Launcher version. About the MySQL database, I know that you need a plugin called VaRest (https://wiki.unrealengine.com/VaRest_Plugin), but using it is a mystery to me. I would also love to learn more about this stuff, but I couldn’t find proper description about it anywhere yet.

Hope I could still helped a bit.

I never used the PlayeerState so far.
I handle all my gamelogic in the controller. I also store all my data in there.
For example, (with the FPS template)

When the Character “InputActionFire” triggers, the player controller is consulted if firing is possible (enough ammo?)
3efbfaf9d01b72fc29fb5068a356ef2975b7fdf9.jpeg

The player controller itself contains several blueprint components to keep things not too cluttered there…

However I dont know how things are multiplyer-wise…

just a heads up that playercontrollers are not replicated

the client has their own and the server has its own copy for each client. so if you wanted to say have a menu that allowed other players to see stat points for a character they would not be able to access it from the player controller it would need to be sent into the character then accessed (im self-learned don’t take this as 100% accurate though)

You are absolutely right, I’m sorry, I didn’t pay enough attention to that sentence.