I am currently trying to build a simple little game, to get the hang of UE4. With Blueprints, you are able to make very fast progress, but some things still riddle me. This is mostly due to the confusing fact, that you often dont know who you are. Confusing right?
Example:
In some Bluprints, you might want to get the Pawn of the Current player. When you do this, you often will have to use the index of the player you want to access. For single player games this is not the biggest deal, since you will only use 0 and this will work like a charme. But I imagine if you want to add Multiplayer support to your game, this will come to bite you back. Now, here is basically the core question that I have: What do I need to do to make a singleplayer game, to be best prepared to add networking in the future. My Guess was, that Player State might play a role in this. But PlayerState currently is a bight mistery to me, that I cannot solve myself. In all the examples and tutorials I see, PlayerState is never used. It would be great if someone could enlighten me with that, by using a real life example maybe?
Let’s make up a very common scenario:
Where would I save a Character’s Hit Points. Is there a difference between Player Characters and NPCs? Does it belong to the Pawn? The Player Controller or the Player State?
Make it that it is most portable to a Multiplayer Experience aswell.
Hey, it is not all that hard, I am suprised that nobody anwsered here. I will try to go through it one by one:
Well thats right, in multiplayer you don’t really want to access the remote PlayerController from the server. You pretty much handle the Pawn, the physical representation in the world. Indexing doesn’t really work. So you basically want to do it the standard way, which is letting the GameMode spawn and handle possession between Pawns and Controllers.
Well it’s always the best to implement multiplayer from the very beginning, because it always includes a heavy amount of replication that often needs a bit of planning to get right and pretty much every actor needs it’s own bit of replication code.
If you really want to start with single player and then add multiplayer on top, then you’d have to rework pretty much every actor anyways, so I wouldn’t bother until it is time for it. But still, building the multiplayer features from he beginning is always the better bet.
Logically, you would store that information in the Pawn. If the Pawn gets hit, it loses it’s HP. The Controller kinda is the Mind of the Pawn, it’s brain if you will. The PlayerState is nothing else but a layer of abstraction that allows you keep your classes clean. You can store additional information, but it’s optional.
The physical representation should be the same(a Pawn), only the Controller is different. Where player controlled Characters have a PlayerController and NPC’s an AIController.
You should check the game framework documentation out for this.
In general I would advice you to build a very small project that has network functionality. I presume you would learn enough to start a bigger multiplayer project right away.
The Playercontroller only exists one your local client and on the server. So other Clients cant access values from your playercontroller (playername for example). Since its possible that a playercontroller possess other pawns its also not recommended to save your playerinfromation there. So where to store my values ? right… in the playerstate. The Playerstate exits on all pawns and always match its playercontroller.
the following Image form ue3 explanes this really well. (playerreplicationinfo is just renamed to playerstate)
I watched the BP Networking tutorial and it allready helped a bit. I might actually go and try to get networking in my game from the get go. In answer hub I read, that on a client, the index 0 always refers to the local player? So if I want to render something in my HUD (which is client side only) that belongs to the local player, i should be safe to use index 0 in this cases? Is this true?
Also another question would be, if you can react to a replication variable on that has been replicated inside you playerstate, from your pawn class. Or would I have to notify the pawn from the playerstate itself? If so, does the playerstate know which pawn it belongs to? Ot would I have to poll value in tick?
edit: dont mind the cast to myplayerstate - that node shouldnt be there atm but i would like to expand my state with more information, i assume inheritance is the way to do it. it just need to find out how to tell the game to use my class
oooh i feel dumb now - **thanks for helping me find that!! ** those pull downs with one option are sneaky - just this morning i had another issue with the server default game mode not being set